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?

Rusty Rob
  • 16,489
  • 8
  • 100
  • 116

3 Answers3

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.

Jeff Hubbard
  • 9,822
  • 3
  • 30
  • 28
  • I'm confused. I'm using the FormData append method https://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. – Rusty Rob Dec 09 '13 at 02:33
  • Set headers to: `headers: { 'Content-Transfer-Encoding': 'utf-8' }` instead of what you have now. – Jeff Hubbard Dec 09 '13 at 02:45
  • 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 – Rusty Rob Dec 09 '13 at 02:48
  • Hmm. I'm out of ideas, then. Sorry. – Jeff Hubbard Dec 09 '13 at 04:15
  • 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. – Rusty Rob Dec 09 '13 at 21:39
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"
Rusty Rob
  • 16,489
  • 8
  • 100
  • 116
0

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

Tiago Medici
  • 1,944
  • 22
  • 22