73

What is the HTTP "content-type" to use when returning a blob of bytes in response to a client's GET request?

In this case, the information payload is an object serialized using Python's Pickle library.

Chris Dutrow
  • 48,402
  • 65
  • 188
  • 258
  • 1
    Note that everything is a 'blob of bytes', but if there's indeed to known mimetype, `application/octet-stream` is a good pick. – Evert Nov 04 '12 at 23:25

3 Answers3

116

You should use application/octet-stream.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
7

You should use the proper MIME type:

application/python-pickle

This is the de-facto standard (this mean: it is not application/pickle or application/pickle-python).

RFC2046 states:

4.5.3. Other Application Subtypes It is expected that many other subtypes of "application" will be defined in the future. MIME implementations must at a minimum treat any unrecognized subtypes as being equivalent to "application/octet- stream".

So, to a non-pickle-aware system, the stream will look like any other octet-stream (you are not doing anything which will break existing apps), but to a pickle-aware system this is vital information.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
thedayofcondor
  • 3,860
  • 1
  • 19
  • 28
  • 9
    That's not the "proper" type (it's not in the registry) – Julian Reschke Nov 05 '12 at 08:11
  • 2
    It is the de-facto standard. RFC2046 states: 4.5.3. Other Application Subtypes It is expected that many other subtypes of "application" will be defined in the future. MIME implementations must at a minimum treat any unrecognized subtypes as being equivalent to "application/octet- stream". So, to a non-pickle-aware system, the stream will look like any other octet-stream, but for a pickle-enabled system this is vital information – thedayofcondor Nov 05 '12 at 08:54
  • 23
    Can you provide references for "This is the de-facto standard" ? – bukzor Jan 08 '13 at 17:30
0

To pass a bytes object from Angular to Django, removing the content-type from headers works as well, i.e.

const httpOptions =  {headers: new HttpHeaders({})}
const formData = new FormData();
formData.append('file', file);
this.http.post(myAPI(), formData, httpOptions).subscribe(

where file is a bytes object e.g. a (pickle) file uploaded by user.

Using application/octet-stream might throw a 415 Unsupported media Type in http.post Angular request error.

vpap
  • 1,389
  • 2
  • 21
  • 32