/ tuesdaytooling

Tooling Tuesday: Filestack

I needed to send an image to a public URL, so I did a bit of Googling and found this.

So what is it?

Filestack is...

The File Handling Service for Developers
Powerful APIs that allow you to upload, transform and deliver any file into your app.

So can I translate that from marketing speak?

Using Filestack I can upload images, files to a Content Delivery Network (CDN) and share them using different programming languages. It offers a simpler process to sending files than say Google Drive / Dropbox etc. But it is really meant as a CDN to share files publicly, so don't use it for private / sensitive / secret stuff!

If you like what you read...
Sorry to interrupt! But would you like to buy me a cup of coffee? It helps me to pay for hosting this blog, and to buy stuff to hack from Poundshops / Dollar Stores which are used in free projects on this blog. Thanks!

So how do I use it?

First sign up for a free account and follow the email verification process.
When you login to Filestack you will see the dashboard, and in the top right is your API key, you will need this later.
Other areas of the dashboard show how many uploads you have made, and how much bandwidth has been used to serve the files.

The free tier receives 100 uploads per month and 1GB of bandwidth. Plenty for a quick project.

So how do I use it...with Python3?

Install via pip3

Linux / Mac

sudo pip3 install filestack-python


pip.exe install filestack-python

So give me an example on how to use it..please!

Here is a simple project to upload an image to Filestack, and get the URL using Python3.
The sample image is this magnificent beast! Saved as bigles.jpg in the same directory as this code will be. Obviously change this to a file that you want to use, unless you want to upload an image of me...which is a bit weird.

First I import the Filestack library, specifically the Client class.

from filestack import Client

Then I create an object called client which will be used to connect our code to the Filestack API. Don't forget to paste your API key between the quotation marks (" ")

client = Client("YOUR API KEY HERE")

Next I create another object called new_filelink and in there I instruct the code to upload the bigles.jpg image to Filestack.

new_filelink = client.upload(filepath="bigles.jpg")

Lastly I print the URL for the uploaded file.


Save the code as uploader.py and take it for a test.

So do you have another example?

Sure, in this example I used the webbrowser library, which is built into Python, and the easygui library which can be easily installed via pip3, click on the link to learn how. I used these two libraries to create a GUI tool to upload a file to Filestack and then open the URL of the uploaded file in my default web browser.

from filestack import Client
import webbrowser
import easygui
client = Client("YOUR API KEY HERE")

Easygui has a simple way to create a window to open a file, fileopenbox will open a file dialog using the operating systems default.

file = easygui.fileopenbox(title="Select file to upload")
new_filelink = client.upload(filepath=file)

To open our default web browser I simply tell it to do so and pass the URL as an argument.


I saved the code and ran it. Easygui popped up a file open dialog box and I selected a file to upload.
Then I saw the file appear in my browser!

Happy Hacking