File transfer over HTTP
Asked Answered
T

2

7

As far as I know it is possible to transfer binary files over HTTP protocol. But HTTP is a text-based protocol, the typical HTTP response frame looks as follows:

HTTP/1.1 200 OK
Date: Wed, 23 May 2012 22:38:34 GMT
Content-Length: 438
Content-Type: text/html; charset=UTF-8

Here goes content

If so, how should binary file be encoded in this frame? What is the Content-Type? Is the content encoded with base64 - same as attachments in POP3 protocol? Or it is raw data (is it possible not to cause problems if so?)

Titanite answered 23/5, 2012 at 18:42 Comment(0)
B
9

The header fields are text based, but the actual payload is binary. You can transfer whatever you want.

And no, it doesn't have anything to do with the Content-Type. That is just a label so that the recipient knows how to process the data; it does not affect the format in the protocol itself.

Burch answered 23/5, 2012 at 20:29 Comment(0)
G
0

Binary files are usually transferred with the Application/octet-stream mimetype (unless they match another more specific mimetype of course). For transmission you use the raw data - no base64 needed.

Gillard answered 23/5, 2012 at 19:12 Comment(1)
but this is text-based protocol, what about new-line characters encoding and bytes order?Titanite

© 2022 - 2024 — McMap. All rights reserved.