Missing boundary header error 400 with REST JS

Hello,

I am trying to upload a photo to Backendless using the below: File Upload - Backendless REST API Documentation.

with correct applicationID and app_key (i tested the request with postman and it was successful).

The problem is when i use JS (Angular) - i get the below error:
(also in the title)
image.

My question is what headers to use - in both Postman and Anguar I am using
Content-Type: multipart/form-data. There is no difference - or at least not something that is manually inserted.

And what shuld be the body of the request - there is no valid example in the dcumentation?

Thanks,
Ivan

Hello @ivan_ganchev

Welcome to the community!

There is a REST example in the doc:

curl -H Content-Type:"multipart/form-data" \
--form upload=@test.txt \
-X POST \
-v http://api.backendless.com/APP_ID/API_KEY/files/txtfiles/test.txt

I assume the question is more related to how to send a file using Angular, isn’t it?
You should compose a Form (append a file) and send it to the server.

if it works with Postman you can generate code for various platforms/langs/env/libs etc.

I am just wondering why don’t you use our JS-SDK?
There you can find methods for all the APIs

Regards, Vlad

Hello Vlad,

Thank you for your quick responce.

The question is how to transform this
image
into this:
image
image
so i can intercept it
image

I want a centalized spot (interceptor) where to add logic to all requests.

The question is why the header is not enough according to the error and the documentation?
I tried adding boundary to the headers but without success.

Thanks & regards,
Ivan

Actually, I’m not aware of how this.http.post works, but I believe you need to create a FormData instance firstly and append a file to the form.
Have you asked how to upload file in the Angular community?

The question is why the header is not enough according to the error and the documentation?
I tried adding boundary to the headers but without success.

no, to upload a file to the server is not enough just add a header, check this post on how to send files from JS

Hi Vlad,

Thank you again for the information.

I found the solution to the problem - the headers should NOT be set to Content-Type: multipart/form-data - the browser is doing it automatically, the file is uploading and the error is no longer present.

Best regards,
Ivan