Post an image thru Web Api

Hello,
I have the following web api:http://apis.laamistad.edu.uy/api/FileUploading/FileUpload
that allows me to post files to the server.

I am trying to build an app in ai2 that calls this api but with no success
This is the blocks to call it:

Error i get is:
invalid 'httpcontent' instance provided. it does not have a 'multipart' content type header with a boundary parameter.

It works well from postman:


Any help is much appreciated.

Shouldn't you move that POST block to after both blocks that prepare the Web component for the POST?

yes sorry, i updated the code so many times that i ended up misplacing the blocks.
Anyway i am still getting the same error.

As I understand, there is no "multipart/form-data" option in App Inventor. You will need to try other content types...

Also, put your request headers above your url.

i did change the headers above the url.
Still gettting the same error.
If there is no multipart/form-data in app inventor, how do we do to post a file?
thanks

Hi Eduardo

You are somewhere between a rock and a hard place unfortunately. The normal content description for your task would actually be "image/png" (or whatever file types you use). App Inventor is compatible with that content type, as are all the major browsers, but the site you are sending to apparently only supports the multipart type - I was hoping we could fudge it - no luck so far.

This is the code that works for App Inventor but apparently not the site concerned (insecure site) . Note that the Request Header should simply be "content" and when sending only one image we probably do not want to keep the connection alive.

Reference: HTTP headers | Content-Type - GeeksforGeeks

Edit: Updated image and Project File. I was wrong about the header parameter, it should be "Content-Type".

Note that, if we use multipart/ in the header, what is actually expected is something like an email file. In such files, a boundary is inserted between the types of content. When we just post an image file (obviously not mixed) we get an error about the boundary missing.

Given this, I do understand how PostMan is working - it's making a genuine form file, not just sending an image, though the image and a boundary are the only contents.

You could try to do this with App Inventor:
Assemble a file with .eml as it's type and with a bespoke boundary (as described by Geeks for Geeks) and the image concerned.
Possibly the best approach would be to send an email to yourself, with test content, so that you can see how to assemble the file.

PostMedia.aia (5.1 KB)

...... another possibility of course, if you have any influence, is to ask the site administrator to permit other content types.

when you refer to the site administrator, you mean the web api creator (myself) or where the web api is hosted (godaddy)É
thanks

.... well, I would have thought the api - but you would know that as the creator?

If the api does not stipulate the types accepted, than a chat with GoDaddy tech support is required.