Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError with accentuated filenames #32

Closed
StanBoyet opened this issue Oct 31, 2015 · 5 comments
Closed

SyntaxError with accentuated filenames #32

StanBoyet opened this issue Oct 31, 2015 · 5 comments

Comments

@StanBoyet
Copy link
Contributor

Hi guys,

It seems that I have a problem with accentuated filenames (here, 3ème_étage.JPG, 🇫🇷 people ... 😁 )

I don't quite know where to start. Is this react-s3-uploader related ? Or does it come from my Rails server ?

Thanks for the awesome work. We're rolling it in production in a few days :)

The error :

Uncaught SyntaxError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'inline; filename=3ème_étage.JPG' is not a valid HTTP header field value.S3Upload.uploadToS3 @ bundle.js?body=1:52653(anonymous function) @ bundle.js?body=1:52670(anonymous function) @ bundle.js?body=1:52610onReadyStateChangeReplacement @ includes.js?v=9db1f8db18400644bd5c7449e5295620:561
bundle.js?body=1:51078 Object {productType: Object, itemId: 1446286749503, options: Object, price: Object}
@StanBoyet
Copy link
Contributor Author

My bad, I'm pretty sure it's because I don't escape them while getting the signed url from my server ...

@seanadkinson
Copy link
Contributor

Must be this line that is failing.

There must be restrictions on the encoding of characters for setting headers or something (I'm really not sure). Looks like this StackOverflow question says that only US-ASCII characters are allowed.

I went looking at the jquery source code to see if they do anything special when setting request headers, and here where they take in the headers, and here where they set them, neither does any encoding.

You could try to encodeURIComponents on the filename, but not sure that would be correct. If you come up with a solution, and want to submit a PR (or let me know what the solution is, and I can plug it in), we'd love to have it.

Thanks.

@StanBoyet
Copy link
Contributor Author

http://stackoverflow.com/a/22935139/2726340
This replacement is basically what I'd like to implement, as I don't really want to decode/encode everytime either on server or client side. As it's not really standard, I don't think I should submit it... Though I'd like to have your input on how I could plug it in, as I "just" import your component, I can't manage this on my end... Or could I ?

Thanks

@seanadkinson
Copy link
Contributor

Probably would need a PR for this. Just need to do some extra work on this line: https://github.com/odysseyscience/react-s3-uploader/blob/master/s3upload.js#L63

StanBoyet added a commit to StanBoyet/react-s3-uploader that referenced this issue Nov 13, 2015
Library from this SO answer : http://stackoverflow.com/a/9667817/2726340
I added a normalize() call to be sure about the encoding. On my mac, it appears that my filenames were in NFD, the library was in UTF8, so nothing was matched.

Now it seems to be working fine. Don't hesitate to make changements if necessary of course.

PR from issue odysseyscience#32
@seanadkinson
Copy link
Contributor

Pushed v1.2.0 that addresses this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants