Android Question how to upload image file using imgbb API?

dongsool

Member
Licensed User
Longtime User
I'd like to upload an image file.

https://api.imgbb.com/

curl --location --request POST "https://api.imgbb.com/1/upload?expiration=600&key=YOUR_CLIENT_API_KEY" --form "image=R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"

I succeeded in command window.

imgbb:
Private Sub Button1_Click
  
    Dim base As String = Base64EncodeDecodeImage.Base64ImageToString(File.DirAssets,"test.jpg")
              
    Dim hj As HttpJob
    hj.Initialize("hj",Me)
  
    Dim sb As StringBuilder
    sb.Initialize
    sb.Append($""key=MY_KEY&image="$).Append(base).Append($"""$)
    Log(sb.ToString)
  
    hj.PostString("https://api.imgbb.com/1/upload",sb.ToString)
    wait for (hj) JobDone(hj As HttpJob)
    Log(hj.GetString)
  
End Sub

If I execute the code as above, an error will occur.

ResponseError. Reason: , Response: {"status_code":400,"error":{"message":"Invalid API v1 key.","code":100,"context":"Exception"},"status_txt":"Bad Request"}

MY_KEY is right

I need your help. Thank you.
 
Last edited:

dongsool

Member
Licensed User
Longtime User
thank you. I modified it and tested it.

postmultipart:
Private Sub Button1_Click
       
    Dim b64 As Base64Convert
    b64.Initialize
    Dim base As String = b64.EncodeFromImage(File.DirAssets,"test.jpg")

    ImageView1.Bitmap = b64.DecodeToImage(base)

    Dim j As HttpJob
    j.Initialize("",Me)
   
    Dim m As Map
    m.Initialize
    m.Put("key","39ec6479229e77e4dfe96b3135c2???")
    m.Put("image",base)
       
    j.PostMultipart("https://api.imgbb.com/1/upload",m,Null)
    wait for (j) JobDone(j As HttpJob)
    Log(j.GetString)
   
    j.Release
   
End Sub

But there's been no response this time.

Do I also need to use file parameters?

And the base64 conversion library used in the first post was not working properly, so I changed it to another library.
 
Last edited:
Upvote 0

dongsool

Member
Licensed User
Longtime User
It's working.

Thank you very much.

imgbb:
Private Sub Button1_Click
        
    Dim b64 As Base64Convert
    b64.Initialize
    Dim base As String = b64.EncodeFromImage(File.DirAssets,"test.jpg")

    ImageView1.Bitmap = b64.DecodeToImage(base)
    
    Dim m As Map
    m.Initialize
    m.Put("image",base)
    
    Dim j As HttpJob
    j.Initialize("",Me)
    j.PostMultipart("https://api.imgbb.com/1/upload?key=YOUR-KEY",m,Null)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    End If
    j.Release
    
End Sub
 
Upvote 0
Top