Using imgBB api in livecode (solved)

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Using imgBB api in livecode

Post by FourthWorld » Sat Sep 26, 2020 10:10 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mimu
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 76
Joined: Tue Mar 05, 2013 7:00 pm
Location: Berlin
Contact:

Re: Using imgBB api in livecode

Post by mimu » Sun Sep 27, 2020 12:25 am

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
Attachments
imgbbUpload.livecode.zip
(3.79 KiB) Downloaded 330 times

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Using imgBB api in livecode

Post by FourthWorld » Sun Sep 27, 2020 12:43 am

"Working example"? You resolved the issue?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mimu
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 76
Joined: Tue Mar 05, 2013 7:00 pm
Location: Berlin
Contact:

Re: Using imgBB api in livecode

Post by mimu » Sun Sep 27, 2020 2:13 am

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Using imgBB api in livecode

Post by FourthWorld » Sun Sep 27, 2020 2:27 am

Well done, Mimu. Thanks for posting that.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

BigameOver
Posts: 39
Joined: Thu Jan 23, 2020 5:56 pm

Re: Using imgBB api in livecode

Post by BigameOver » Sun Sep 27, 2020 8:51 am

WOW! Thank you guys so much, I have been working on this for days and I appreciate you! :D :D
It does work!

Post Reply

Return to “Internet”