Skip to content

Commit

Permalink
Do not append file into FormData if already has !
Browse files Browse the repository at this point in the history
Sometimes people may want to minimize the file size and will do some compress then set the new compressed file into the form.
Therefore when data already contains new file, do not append the original one.
  • Loading branch information
ablipan committed Mar 16, 2016
1 parent dc8968e commit c5219e8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions SimpleAjaxUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1756,14 +1756,22 @@ ss.XhrUpload = {

if ( opts.multipart === true ) {
var formData = new FormData();


var hasFile = false;

for ( var prop in params ) {
if ( params.hasOwnProperty( prop ) ) {
if (prop === opts.name) {
hasFile = true;
}
formData.append( prop, params[prop] );
}
}

formData.append( opts.name, fileObj.file );

if (!hasFile) {
formData.append( opts.name, fileObj.file );
}

this.log( 'Commencing upload using multipart form' );
xhr.send( formData );

Expand Down

0 comments on commit c5219e8

Please sign in to comment.