Page 2 of 2

Re: Using imgBB api in livecode

Posted: Sat Sep 26, 2020 10:10 pm
by FourthWorld
404 tells you the URL you're using is wrong. I'm not familiar with that API so I can't help with that part of it, but if that project has a forum I'll bet they can get you sorted on that part pretty quickly.

Re: Using imgBB api in livecode

Posted: Sun Sep 27, 2020 12:25 am
by mimu
Hi, I've put together a small working sample stack to post to the imgBB Api.

Download it, open the stack script, add you API-Key and it works.
Select a file to upload,
it will appear in 2 Images of the card, img1 is referenced, image 2 contains the imagedata.
When you hit "upload Image 1" the Image is read from disk and the postdata is assembled using libURLMultipartFormData
When you hit "upload Image 2" the Imagedata is taken out of the image object (myImg2) and transferred to the upload function.

The result is shown in a TreeView widget at the bottom.


Set a breakpoint in line 71 and watch the variables, here you see how the function upload2imgbb is used.
Set another breakpoint in line 94 and look into the variable tform.

Line one contains the http headers which will be sent,
Line 2 to last line contains the data which will be posted.

I'll hope it helps

Re: Using imgBB api in livecode

Posted: Sun Sep 27, 2020 12:43 am
by FourthWorld
"Working example"? You resolved the issue?

Re: Using imgBB api in livecode

Posted: Sun Sep 27, 2020 2:13 am
by mimu
Yes it works, tested it

From the imgbbdocs:
curl --location --request POST "https://api.imgbb.com/1/upload?expirati ... NT_API_KEY" --form "image=R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"

It is send as form data

Code: Select all

put  base64Encode(pImageData) into tFile
put libURLMultipartFormData (tForm,"image", tFile) into tError
 if tError is not empty then
      Answer tError
  else
 set the httpHeaders to line 1 of tForm
 post line 2 to -1 of tForm to url tUrl
I 'll hope it will help BigameOver

Re: Using imgBB api in livecode

Posted: Sun Sep 27, 2020 2:27 am
by FourthWorld
Well done, Mimu. Thanks for posting that.

Re: Using imgBB api in livecode

Posted: Sun Sep 27, 2020 8:51 am
by BigameOver
WOW! Thank you guys so much, I have been working on this for days and I appreciate you! :D :D
It does work!