Closed is-blackhole closed 8 years ago
Try setting the encodeCustomHeaders
option to true
.
Just tried it, no luck, still got Uncaught SyntaxError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'русский.yml' is not a valid HTTP header field value.
Looking for code in _uploadXhr:
for ( var i in headers ) {
if ( headers.hasOwnProperty( i ) ) {
if ( opts.encodeCustomHeaders && opts.customHeaders.hasOwnProperty( i ) ) {
xhr.setRequestHeader( i, encodeURIComponent( headers[ i ] ) + '' );
} else {
xhr.setRequestHeader( i, headers[ i ] + '' );
}
}
}
only customHeaders will be encoded, but thats not a custom header, but one set at _initUpload method :
headers['X-Requested-With'] = 'XMLHttpRequest';
headers['X-File-Name'] = fileObj.name;
Try using this modified version of the plugin:
I modified line 1522 to look like this:
headers['X-File-Name'] = !this._opts.encodeCustomHeaders ? fileObj.name : encodeURIComponent( fileObj.name );
If that works I'll go ahead and push a change.
yes, its work, thanks!
Glad I could help. Just pushed this change.
All works fine until I have tried file with russian chars (utf-8 name + chromium), I got : Failed to execute 'setRequestHeader' on 'XMLHttpRequest'.
Looks like setting header cause this: headers['X-File-Name'] = fileObj.name;
Think simple encodeURIComponent will fix : headers['X-File-Name'] = encodeURIComponent(fileObj.name);