benefitcloud / ember-uploader

An Ember library for uploading files
MIT License
346 stars 97 forks source link

Add the option to skip form data insertion (won't change default functionality) #163

Open ioan-pop opened 7 years ago

ioan-pop commented 7 years ago

The extra form data that is inserted for files can cause issues on the other hand, I suggest adding a optional property of "skipFormData" (Boolean) to the uploader object. Example:

const uploader = EmberUploader.Uploader.create({
    url: this.get('url'),
    method: "PATCH",
    skipFormData: true
);

Then inside the /addon/uploaders/base.js on line 63 the data can be changed to be:

const data   = !get(this, 'skipFormData') ? this.createFormData(files, extra) : files;

This will skip the form data if the property is set to true, and create the form data if the property is set to false, or is not present.

digitaltoad commented 7 years ago

I guess I don't really understand the problem here. There should be a single FormData. FormData is required (afaik but please do correct me if I'm wrong as I would like to know) for upload via JS.

ioan-pop commented 7 years ago

Hey digitaltoad, you're right, this issue can be closed. Thanks!

ezekg commented 6 years ago

As mentioned in #147, form data is not required, and messes with uploads that should be a binary upload. For example, AWS S3 doesn't support form data (and I'm not sure how it's working for other people, to be honest). I'm using this modified uploader below to be able to upload to S3:

import EmberUploader from 'ember-uploader'
import Ember from 'ember'

const { Uploader } = EmberUploader
const { get, set } = Ember

const BinaryUploader = Uploader.extend({
  upload(file) {
    const url    = get(this, 'url')
    const method = get(this, 'method')

    set(this, 'isUploading', true)

    return this.ajax(url, file, method)
  }
})

I was seeing issues where the uploader would send multipart/form-data, and that data would be stored raw in S3 (including the data boundaries), causing files to become corrupted.