After creating a binary file in the Browser using JavaScript as Uint8ClampedArray
, I am now faced with the task of uploading it to a webserver as if it was selected from a file-picker.
My attempt at this resulted in the following code:
var data = new Uint8ClampedArray(32);
data[0] = 0x42;
data[1] = 0x4D;
postdata = new FormData();
postdata.append('data', new Blob(data), 'test.txt');
fetch('http://localhost/',{
method: 'POST',
body: postdata
});
However, the request generated looks like this:
POST / HTTP/1.1
content-length: 230
content-type: multipart/form-data; boundary=----WebKitFormBoundaryfsPRCG3QGnD2bWZS
------WebKitFormBoundaryfsPRCG3QGnD2bWZS
Content-Disposition: form-data; name="data"; filename="test.txt"
Content-Type: application/octet-stream
6677000000000000000000000000000000
------WebKitFormBoundaryfsPRCG3QGnD2bWZS--
And unfortunately, it results in this Textfile being created :(
6677000000000000000000000000000000
I'm looking for guidance on how to properly create a valid binary Blob(). Thank you!