Sending file via post

Hello. I need to send the file, but i have a problem with sending binary. Something wrong with handling binary data because uploader catches wrong file.

Main.js (sender)
Php uploader (saves catched image to current folder)

What’s wrong with this? Thx.

I don’t see any base64 encoding?

Yeah, there is no base64. So, I’m dont sending this to my script, I’m sending this to rest api server and I cant setup my conditions. Firefox spoils binary data while sending.

You can send as FormData there are many topics here showing how to do this:

If you have a specific example you need help with, post up the code here and we can walk you through it.

I need just send binary in raw (without any hints) to my uploader.

You can upload an arraybuffer, just do .send(arrBufHere) does that work? If you need to have a filename on it you can do send with a blob or file object as well.

Could u get me some examples please? Right now I’m trying to use application/x-www-form-urlencoded with base64 :slight_smile:

Now I’m trying to use this but cant get access to FormData.

You cannot send binary data via http. Therefore you base-64 encode it first. Your code does not base-64 encode the binary file contents, therefore they are not sent properly. Otherwise the code looks correct.

Various versions of Firefox provide cute ways for you to ‘‘apparently’’ send binary data through http, but behind the scenes they are just doing the encoding for you. For example you can send a Blob simply by passing it to XHR.send(), but that won’t send multipart form data so it isn’t good for you.

Firefox does include a FormData API which allows you to send multipart form data without having to construct the string yourself. You can just append key/value pairs to the FormData object and then pass it to your post request. It could be a good solution except you’ve already gone to the trouble of writing all the code to do this, so it seems a bit pointless to start again. Note that some features of the FormData API are not available in Firefox versions before 44. Also, this feature is part of the latest standard but is not well supported (or supported at all) by other browsers.

Thx for info. I need realization only for 40<=. How I can do it? With FormData (or analog) or something else. I can’t find examples with sending binary with base64 via sdk.

Base64 string is correct, but how explain to server that I want it used to decode?

Now I have this. It successfully sends file to my uploader, but I need other. Target server want content-type header (commented), but how I can handle it? I’m trying to realize this api. My first script successfully sends files to target server, but having problem with binary.

Your code does not base-64 encode the binary file contents

I don’t know how to do it. Just encoding file data gives nothing (server correctly receives file consisting of base64 string :smiley: ).

1 Like

All say about “base64 content”, but no one (including google) can explain it…