0

I am trying to form a Content-Type: application/octet-stream PUT request from JavaScript where the body will be raw binary (byte[]). I have a Base-64 encoded string of the binary data which is a random file content. I need to decode this back to a byte array and put it into the request body.

The curl command I could use to do this is:

curl -v -X PUT --header "Content-Type:application/octet-stream" --data-binary "@myfile" http://localhost:8080/my-services/myapi 

How can I do that in JavaScript?

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • 1
    You want to do this in a *browser*, right? Not NodeJS or similar? – T.J. Crowder Aug 05 '16 at 16:31
  • And if so, are you using jQuery? Because if you are: http://stackoverflow.com/questions/19959072/sending-binary-data-in-javascript-over-http (pretty much answers this even if you aren't using jQuery, if you're doing this on a browser). – T.J. Crowder Aug 05 '16 at 16:32
  • I've added a non-jQuery version of the answer there, so this is a duplicate if you're doing it from a browser. – T.J. Crowder Aug 05 '16 at 16:37
  • Stack Overflow is **really active**. Please don't post a question and disappear. Stick around for a while so you can answer questions from people trying to help you. – T.J. Crowder Aug 05 '16 at 16:48

0 Answers0