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

Upload doesn’t work when non-english characters are presented in the filename #128

Closed PeterMozesMerl closed 8 years ago

PeterMozesMerl commented 8 years ago

Upload doesn’t work with either über.png or éber.png. These are valid characters in file names.

Uncaught SyntaxError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'éber.png' is not a valid HTTP header field value.

Chrome says it’s line 1499 on the demo site.

Note: I have an (~1-2 years) old version of Simple-Ajax-Uploader in production. Fortunately, it has no problem with the same file.

PeterMozesMerl commented 8 years ago

Unfortunately, I had no time to read the whole source code, so I’m wondering if there is a reason to not always encode the filename.

headers['X-File-Name'] = !this._opts.encodeCustomHeaders ? fileObj.name : encodeURIComponent( fileObj.name );

I think removing the condition and using the latter arm from the line above would solve the issue. Would this conflict with the line 1499 area? (Below)

if ( opts.encodeCustomHeaders && opts.customHeaders.hasOwnProperty( i ) ) {
    xhr.setRequestHeader( i, encodeURIComponent( headers[ i ] ) + '' );
} else {
    xhr.setRequestHeader( i, headers[ i ] + '' );
}
LPology commented 8 years ago

I just renamed files to both über.png and éber.png and it worked fine. Are you setting charset=UTF-8 on your page?

Can you try it on the demo and let me know what happens?

https://www.lpology.com/code/ajaxuploader/

LPology commented 8 years ago

Fixed with 2.3 release. Closing out. Feel free to reopen if you have any issues.