httpbinarymultipartw3c

Can a multi-part message contain raw binary content?


I want to transfer binary content via HTTP. I have doubts, whether sending a "multi-part" body consisting of the binaries and a short meta-data content is a good idea.

Can I send binary content in a multi-part message, without having to convert it (i.e. as BASE64)?


The RFC1341 specification does not seem to forbid it - but a non-escaped binary content could coincidentally contain the encapsulation boundary, couldn't it?

I wanted to see the data in my chrome's developer toolset - but the interesting part is not displayed.


Solution

  • Clearly, yes. That's how most multi-Range requests are answered.

    The size start and end positions defined in the Content-Range are used to calculate the size to read from the incoming data so it can really be absolutely anything, it just needs to be the exact right size (even when it is just text!)

    Further, the content can be compressed. I'm not sure how each browser support sub-part compression, though.

    Of course, you should have a Content-Type describing the content of the part anyway.

    For example:

    --<boundary>
    Content-Type: image/jpeg<cr ln>
    Content-Range: bytes=0-999/64911<cr ln>
    <cr ln>
    <binary JPEG data><cr ln>
    --<boundary><cr ln>
    ...(2nd part)...<cr ln>
    --<boundary><cr ln>
    ...(3rd part)...<cr ln>
    --<boundary>--<cr ln>        (last boundary)