Posting an Image to Imgur - works with Postman, error with App Inventor 2

Hello,

I have been seeking to upload an image to Imgur using the API end-point for upload. I tested the API end-point with Postman. It works fine and here is what Postman gave as the code for the cURL request.

Now I try making the POST request in AppInventor and get an error. The Imgur server rejects the POST request with 400 status ("Bad request").

I have tried the following:

  1. POST text with Content-Type as "mutipart/form-data"
  2. POST file with Content-Type as "image/jpeg"
  3. Structuring information with Dictionary or List-of-Lists
    None of these have worked.

The file location is hardcoded for testing. I have tried working with the image in the following ways:

  1. Using the object captured by camera in App Inventor
  2. Using the object stashed in the "Selection" attribute of ImagePicker
  3. Converting image to base64 string (offline) and passing the string.
    Based on the Postman code, I have hardcoded the filepath in the example. None of these have worked either.

Can you please suggest other options to try, including perhaps an alternative image hosting service known to work with AppInventor? I would like to avoid installing an extension unless absolutely necessary.

Cheers!

theoretically it would be possible using the web component…
however the web component does not support multipart/formdata, i.e. a mixture of binary data and text, so the web component unfortunately is not able to do it

you could try to use the Terminal / Shell Extension by @Juan_Antonio , but I’m not sure, if this will be possible there… you might want to try it and let us know, what you find out…

EDIT

this should be doable using the web component...
I'm not sure, if you can use dictionaries as replacement for list of lists?
in the request header you forgot your credentials after "Bearer", see also this example https://puravidaapps.com/dropbox.php
you might want to provide a screenshot of your updated blocks

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

That file name "blocks (7).png" looks deadly

@Taifun Thank you for the helpful suggestions. I will try the Dropbox solution and follow the other leads you have provided. I will post an update with the results a little later. The extension to run Linux commands in App Inventor sounds very promising. However, Malwarebytes blocked Kio4.com for malware. This is a false alarm, right? Thank you very much for your help.

@Juan_Antonio might want to answer this question...
Taifun

1 Like

Malwarebyte has already unblocked my domain kio4.com

1 Like

I went with the Dropbox-based solution based on @Taifun's suggestion and made some modifications of my own. My goal was to have an image hosted with a URL link for further analysis with a REST API service for text extraction, etc. I followed steps as follows:

  1. Take an image with the camera component and get filename with full path.
  2. Upload the image with Dropbox API using the end-point for upload.
  3. Get a shareable link from Dropbox using the end-point for creating shared link.
  4. Modify the shared link for a URL that serves just the image minus extraneous HTML.
  5. Show the image in WebViewer component with the URL to verify all-OK.

The screenshot with blocks is below. I noted the following:

  • Dropbox API gives two types of token to use for authentication with REST API end-points - temporary and permanent.
  • Various permissions need to be explicitly set via Dropbox developer account to upload or share files and a new token must be generated with every change.
  • The shareable link generated by Dropbox needs to be modified to link just to the image.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.