3

I'm uploading a form with files, text etc to the appengine blobstore:

$http({
    method: 'POST',
    url: the_url,
    transformRequest: formDataObject,
    data: event,
    headers: {'Content-Type': undefined}
})

The request sends successfully with the follwing header:

Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryYeRxOO7y3qHNWd83

When I try setting the content-type to "multipart/form-data;charset=UTF-8" I lose the boundary and get an error in the response: Bad content type. Please use multipart.

What is the correct way to add the UTF-8 charset?

3 Answers 3

2

According to RFC 1341:

As stated in the definition of the Content-Transfer-Encoding field, no encoding other than "7bit", "8bit", or "binary" is permitted for entities of type "multipart". The multipart delimiters and header fields are always 7-bit ASCII in any case, and data within the body parts can be encoded on a part-by-part basis, with Content-Transfer-Encoding fields for each appropriate body part.

So you have to use Content-Transfer-Encoding instead of Content-Type in this case.

Sign up to request clarification or add additional context in comments.

5 Comments

I'm confused. I'm using the FormData append method developer.mozilla.org/en-US/docs/Web/API/FormData. I don't know how/where to set the Content-Transfer-Encoding. Perhaps I need to base64 encode my text.
Set headers to: headers: { 'Content-Transfer-Encoding': 'utf-8' } instead of what you have now.
with headers: { 'Content-Transfer-Encoding': 'utf-8' } I get: Refused to set unsafe header "Content-Transfer-Encoding" angular.js:6649 (anonymous function) angular.js:6649 q angular.js:203 (anonymous function) angular.js:6648 y angular.js:6518 g angular.js:6252 r angular.js:9042 r angular.js:9042 (anonymous function) angular.js:9128 g.$eval angular.js:9953 g.$digest angular.js:9809 g.$apply angular.js:10039 (anonymous function) angular.js:15394 (anonymous function) angular.js:2246 q angular.js:196 Nc.c
Hmm. I'm out of ideas, then. Sorry.
I've marked your question as correct since it shed some light on the situation & the fact that I didn't need utf-8 there.
2

My solution was not to change anything:

It turns out using headers: {'Content-Type': undefined} was correct. Everything is now working (and I only changed the backend).

Trouble was that webob was ignoring encodings and hence I thought the encodings were wrong. Upgrading webob fixed this issue. The reason this was hard to detect was because the development server was using the new webob by default whilst the production was defaulting to an older webob version since the new version wasn't specified in app.yaml:

libraries:
- name: webob
  version: "1.2.3"

Comments

0

the charset must be set after all like: Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryYeRxOO7y3qHNWd83; charset=UTF-8

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.