1👍
WebSocket.send() accept different data-types as parameter. You can transfer binary data over a WebSocket in both directions.
On this snippet you can see how to make use of it on the client- and server-side in JavaScript. The Django channels also support binary data.
You can attach any information to the binary data from the file and send it together with the file as a header.
For example, by using 2 (or 3) Byte to indicate the length of the header. Which means, up to 64KB (or up to 16MB) for informations like filename and other infos you might need. In the end, this is similar to a HTTP POST.
The message you send would then look like this:
len of header | header | file
-------------------+------------------------+-----------
00 00 up to FF FF | infos about the upload | binary
Even multiple files would be possible:
< header len >
< header >
< file len >
< file >
< header len file 2 >
< header file 2 >
< file 2 len >
< file 2 >
...and so on
All you have to do on the serverside afterwards is to split the combined message back into it’s parts defined by the length values.