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

Request not utf-8 encoded #1818

Closed
wirob opened this issue Aug 30, 2019 · 5 comments
Closed

Request not utf-8 encoded #1818

wirob opened this issue Aug 30, 2019 · 5 comments
Assignees

Comments

@wirob
Copy link

wirob commented Aug 30, 2019

When uploading a file with special characters like å ä ö ø æ they turn up like åäö ø æ in the multipart-form.

The only time this doesn't happen, is when uploading a .svg.

I have read that one needs to set <meta charset="utf-8" /> in index.html, but it is set to utf-8 when using create-react-app by default.

const uppyupload = new Uppy({
      meta: { charset: 'utf-8' },
      autoProceed: false
    })
"@uppy/core": "^1.2.0"
"@uppy/react": "^1.2.0"
"@uppy/xhr-upload": "^1.2.0"

The problem, as I see it, it that the individual "metaFields" doesn't set UTF-8 as encoding.

-----------------------------2639272711271912642983551856

Content-Disposition: form-data; name="charset"
utf-8

-----------------------------2639272711271912642983551856

Content-Disposition: form-data; name="relativePath"
null

-----------------------------2639272711271912642983551856

Content-Disposition: form-data; name="name"
Ska�rmavbild 2019-08-29 kl. 14.07.37.png

-----------------------------2639272711271912642983551856

Content-Disposition: form-data; name="type"
image/png

-----------------------------2639272711271912642983551856

Content-Disposition: form-data; name="tags"
åäö

-----------------------------2639272711271912642983551856

Content-Disposition: form-data; name="files[]"; filename="Ska�rmavbild 2019-08-29 kl. 14.07.37.png"

Content-Type: image/png
�PNG

@goto-bus-stop
Copy link
Contributor

Uppy's meta option is for setting form fields. There's no <meta charset> for uploads. Not sure what's causing this! Is this just happening in the devtools or do the strings contain garbage on the server as well?

@ifedapoolarewaju
Copy link
Contributor

ifedapoolarewaju commented Oct 21, 2019

When uploading a file with special characters like å ä ö ø æ they turn up like åäö ø æ in the multipart-form.

@wirob where are you inspecting the multipart-form? Is in the network tab from dev tools or are you getting this behaviour from the server too?

From what I see here, so long as your server handles the data appropriately, all should be fine

@goto-bus-stop
Copy link
Contributor

Closing per above: most likely this is just a devtools display issue and doesn't affect the data being sent. please let us know if that's wrong and we'll reopen!

@wirob
Copy link
Author

wirob commented Dec 17, 2019

Sorry for the late reply.

You were correct, since my dev-tools didn't know which charset to use when displaying the multipart-form all special characters got scrambled.

Is there a reason UTF-8 isn't the default charset?

@goto-bus-stop
Copy link
Contributor

goto-bus-stop commented Dec 18, 2019

I don't know for sure how the devtools choose the charset. For response data, it's usually like this: by HTTP spec, the default charset is ISO-8559-1 or something, if no other charset is given. But many many websites do not specify a specific charset and use a different one, so if browsers followed the spec to the letter, most websites would render incorrectly. So, browsers look at the bytes and try to guess which charset is used.

The FormData API that @uppy/xhr-upload uses for its upload requests uses UTF-8 for strings, is my understanding. But when you upload an image or something, the request also contains the raw bytes of the image, so the request isn't fully valid UTF-8. My guess is that the devtools then uses a similar heuristic as above, and picks a default encoding or something to render the request data.

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

No branches or pull requests

5 participants