Upload file to server

How can I upload an image using Kodular to my own server?
The upload method in Postman is shown in the image below.
Is it possible to use this same upload method in Kodular?

The first image is from the browser (Developers Tools).
The second image is from Postman.

Try the PostFile method from the web component
Taifun

1 Like

And if you’ve already tried something, show the blocks you used.

1 Like

I tried the method shown in the image, but the server responds with error “500”

Usually the first 3 headers you do not need, the authorization looks wrong… my guess is you forgot the text "Bearer " what about providing the headers from postnan?

Example authorization:

Authorization: Contains credentials to authenticate the client with the server, commonly used with bearer tokens for API requests.

  • ​Authorization
  • Bearer eyJhbGciOiJIUzI1NiIsInR5CJ9…

Taifun

2 Likes

I sent several requests to the server without the ‘Bearer’ text, and there was no issue with that.
I believe the problem lies in the file path not being captured correctly, but I can’t figure out why

What about providing a Do it result of the result URI?

use the companion app together with Do it to debug your blocks, see also tip 4 here App Inventor: How to Learn | Pura Vida Apps

see also Live Development, Testing and Debugging

Taifun

2 Likes

Hi @Muhammad_Deshli
Here is your correct Blocks

Filetool by @vknow360

If helpful, mark as Solution :white_check_mark:

1 Like

Thank you for the help
It didn’t succeed; error 1104 appears. :frowning:

image

As you can see, it is a content uri and not a file path, therefore you have to convert it into a file path. One way to do this is to use one of the file extensions as @Glich has shown…

Show your updated blocks including Do it result of the converted content uri and

Taifun

1 Like


error 1104


From the Do it result you can see, that the path seems to be incorrect…

/storage/emulated/0/Download appears repeated, also the filename looks strange?
Did you check, if that file is available in your Download folder?

Also it looks like the postman example uses application/json as header and in the body the file to upload appears in json format. This is not possible like this in Kodular.

Is there an api documentation available? Any link? Is there another method available which does not use form-data?

If not, the following extension might be able to help (taken from the extensions directory App Inventor Extensions | Pura Vida Apps)

  • HttpUtil Extension by kevinkun, Post a html form with enctype set to multipart/form-data

Taifun

1 Like

Here you will find a file as an example of the case, which includes an API with a token

With utmost respect and appreciation

Sorry, I’m on mobile and can’t check your aia file
Just provide some answers and a link to the api documentation, see my previous questions
Taifun

1 Like

Problem is solved by using my own extension

Here How I did it :slight_smile:

:down_arrow: My extenison Link :
com.syntex.apiutils.aix (9.5 KB)

If helpful mark as solution :white_check_mark:

2 Likes

Thank you for your contribution

@Glich Please start a new thread in category Extensions and present your app extension there including a short documentation and example use.

Also explain the difference to the web component and when or why we should use it instead of the web component

Taifun

1 Like

You’re brilliant!
Thank you—it’s solved thanks to you