I've been building a manual multipart request with Javascript. I would use FormData but it is not stringifable and so I cannot hash it.
I've got the request down but I can't seem to read in the file correctly. I have a hunch it is an encoding issue.
As soon as I read my file in it seems it is corrupted or broken by converting it to a string. The file I've been testing is a PDF.
The original file looks like this:
%PDF-1.3
%ƒÂÚÂÎßÛ†–ƒ∆
5 0 obj
<< /Length 6 0 R /Filter /FlateDecode >>
stream
x•X…nG
When reading the file in with:
reader.onload = arrBufferCallback;
reader.readAsBinaryString(blob);
The output is:
%PDF-1.3
%Äåòåë§ó ÐÄÆ
5 0 obj
<< /Length 6 0 R /Filter /FlateDecode >>
stream
x¥XÉnG½÷WԨܬ»@AÜCC¬H
Which is just plain wrong.
I've tried half a dozen other options like:
var bytes = new Uint8Array(e.target.result);
resolve(String.fromCharCode.apply(null, bytes));
Trying to use a TextDecoder
comes out worse.
All I need is the original file contents in a string form?