LPology / Simple-Ajax-Uploader

Javascript file upload plugin with progress bar support. Works in all major browsers, including IE7+, Chrome, Firefox, Safari, and Opera. No dependencies - use it with or without jQuery.
995 stars 267 forks source link

[bug]duplicate file param when submit as multipart #141

Closed djxhero closed 8 years ago

djxhero commented 8 years ago

fileName pass twice when submit as multipart; I don't know whether it is a bug or not

the first name param just only the custom file name param I named it, and the second is custom file name param and real filename ;

and this not work with my server side program,so I remove the first fileName param.

--------------original param pass like :-------------

------WebKitFormBoundaryOji6kqweUHAmIGy9
Content-Disposition: form-data; name="routeFile"   <---- (this should be remove)

a.txt
------WebKitFormBoundaryOji6kqweUHAmIGy9
Content-Disposition: form-data; name="routeFile"; filename="a.txt"
Content-Type: text/plain

------WebKitFormBoundaryOji6kqweUHAmIGy9--

-----I remove the first file name param , and this work for me-

------WebKitFormBoundaryvkRf5Xz9Ejap9BIY
Content-Disposition: form-data; name="routeFile"; filename="a.txt"
Content-Type: text/plain

------WebKitFormBoundaryvkRf5Xz9Ejap9BIY--
LPology commented 8 years ago

Which version of the plugin are you using?

djxhero commented 8 years ago

Hi LPology, I'm using Simple Ajax Uploader v2.4 . I fixed this problem by removing a statment in _initUpload function:

  _initUpload: function( fileObj ) {
...
//remove following statement ,because  same file name param add in _uploadXhr function twice
//params[this._opts.name] = fileObj.name;

 headers['X-Requested-With'] = 'XMLHttpRequest';
 headers['X-File-Name'] = fileObj.name;
...

because this param actually is added in _uploadXhr function:

 _uploadXhr:function( fileObj, url, params, headers, sizeBox, progBar, progBox, pctBox, abortBtn, removeAbort ) {
        "use strict";
...
 if ( opts.multipart === true ) {
            var formData = new FormData();

            for ( var prop in params ) {
                if ( params.hasOwnProperty( prop ) ) {
                    formData.append( prop, params[prop] );
                }
            }

            // this is right file name param
            formData.append( opts.name, fileObj.file );
            this.log( 'Commencing upload using multipart form' );
            xhr.send( formData );
        }
...

maybe my method not work for non-mulipart situation , hope you can fix that

ablipan commented 8 years ago

I met the problem either with the latest version 2.4.0. Setting the name option with 'file' , there will be two 'file' in the form-data.

------WebKitFormBoundaryys9VdMimwU0Aeiux
Content-Disposition: form-data; name="file"
user/image/296/J99BXJv35iIAQlTrqSbmiJOR6L8Zc8Kj_1453565318410.jpg
------WebKitFormBoundaryys9VdMimwU0Aeiux
Content-Disposition: form-data; name="file"; filename="10.jpg"
Content-Type: image/jpeg

@djxhero +1 Remove that line is working for me. @LPology Maybe it is a bug ?

LPology commented 8 years ago

@ablipan @djxhero This is a good catch. Just pushed an update (version 2.5.0) that removes this line.

Thanks for your input.