Uploading an image and getting a link

Hello everyone,
my first post here!

I am trying to understand how to work with API but I can’t figure out how!

My goal is to upload a picture and getting its link.
After I will use the link to generate a QR code and make the image easy to share.
I have already figure out how to generate a QR code once I have the link.
So what I miss is the upload and getting the link part.

I would like to ask if anyone can suggest me which is the easiest API library that I can use for this purpose. Also it would be very kind if anyone can point me out a workflow to follow or a ‘workaround’ which can help me out with what I want to reach.

I have tried to follow Markus Heckmann’s tutorial ‘Posting images from Touchdesigner to Twitter’. I mostly understand what goes on during the tutorial, but I find it hard to adapt and I get already stuck whenever I need to get the API keys.

Thanks!

1 Like

Hi @renwal76,

is there a possibility for you to just upload the image to a website via ftp or are you planning on using a service like twitter that you want to upload the image to?

For the ftp approach you’d need to have access to a webserver / hosted webspace. You could then use python’s ftplib to upload the image to a particular folder of your choice.

From my understanding you don’t have a particular service in mind that would host your images? A quick search online got me to imgbb.com or imageshack.us who both provide APIs for uploading files.

cheers
Markus

Hi @snaut,
thanks for your suggestions.
Ftp can be actually an handy solution for me.

Regarding the ftplib, I have tried to use the following tutorial:
Python 3 Programming Tutorial - ftplib FTP transfers Python

I wrote this in a text DAT and then run the script.
‘test’ and ‘test1’ are examples of the username and password that I have used for loginning into my account
imgbb.com’ is the website that I want to use for uploading the image
cwd is the location of my file on my PC,
‘star.jpg’ is the name of the file that I want to upload.

 from ftplib import FTP
 
 ftp = FTP('imgbb.com')     
 ftp.login(user='test', passwd='test1') 
 
 ftp.cwd ('C:/Users/Walter Renga/Desktop/')
 
 def GrabFile():
 	fileName = 'star.jpg'
	localfile = open(fileName, 'wb')
 	ftp.retrbinary ('RETR ' + fileName, localfile.write, 1024)
 	ftp.quit ()
 	localfile.close ()
 	 
 def PlaceFile():
 	fileName = 'star.jpg'
 	ftp.storbinary ('STOR '+ fileName, open(fileName, 'rb'))
 	ftp.quit ()	

when I run the script, Touchdesigner and textport look like freezing for 5-10 seconds and then I get the following response in Texport:

python >>> 
Traceback (most recent call last):
  File "</project1/webserver1:op('/project1/webserver1').run()>", line 1
td.Error: File "/project1/webserver1", line 3
  File "C:\Program Files\Derivative\TouchDesigner\bin\lib\ftplib.py", line 117, in __init__
    self.connect(host)
  File "C:\Program Files\Derivative\TouchDesigner\bin\lib\ftplib.py", line 152, in connect
    source_address=self.source_address)
  File "C:\Program Files\Derivative\TouchDesigner\bin\lib\socket.py", line 727, in create_connection
    raise err
  File "C:\Program Files\Derivative\TouchDesigner\bin\lib\socket.py", line 716, in create_connection
    sock.connect(sa)
TimeoutError: [WinError 10060] Could not establish connection. Incorrect response of the connected party after the time interval or no response from the connected host
Results of run operation resulted in exception.

I can’t figure out why this is happening.

Do you have any idea on what is wrong in my script?

1 Like

Hi @renwal76,

here the issue would be that to use ftp you would need access to a webserver that issues an ftp account to you - mostly personal webspace does that.
imgBB on the otherhand does not offer a ftp connection to it’s users rather allowing uploads though an API.

You can get an imgBB API Key here: https://api.imgbb.com and then use the component I just build to upload images to your account. imgBB’s API returns a URL for each saved image which this component saves in a Fifo DAT that is also the output of the component.

The Component makes use of the Web Client DAT which necessitates only a minimal amount of python scripting in the component’s extension.

Hope this helps
Best
Markus

2 Likes

Markus this is absolutely fantastic.
It is working and it’s incredible easy!
Thank you so much! Very helpful!

1 Like

Hi @renwal76
I am trying make QR code use url link with touchdesigner.
But i can’t find how do i this.
Can you share your tutorial?
It will really help me a lot.

Thanks!

6 posts were split to a new topic: Upload video and generate qr code from link