Using the API for Easy Command-Line Image Hosting

Like many of my fellow LowendTalk readers, I sometimes post images on LET and other boards.  To do that, I need an image hosting service.  Going through the work of logging into a web page, uploading through their interface, etc. is tedious.  Wouldn’t it be better to do it with an easy command-line script?  Indeed, and it’s quite easy.

As far as services, I’ve never liked Imgur and while I do like, they don’t have an API.  However, does and in about 15 minutes I had a script that allowed me to upload files and get a URL without any web browser interaction at all.

My requirements were that the script had to work on both Linux and macOS and not require any third-party modules because I didn’t want to have to keep them updated on different operating systems.  There are some nice Python scripts but they require the requests module (which is great, but is third-party).  Likewise while the right thing to do is parse the JSON response with something like jq, that’s a third-party dependency, so I’ll just munge it with a regex.

Here’s code showing how easy it is.

First, create an account on and then login with it.  Then visit and click “Get API Key”.

Here’s the script I’m using, which is modified from the example on their site:


# change this to your actual API KEY
RESPONSE=$(curl -s --location 
--request POST "${API_KEY}" 
--form "image=@"$1"")
URL=$(echo $RESPONSE | sed 's/^.*"display_url":"//' | sed 's/",.*$//')
URL=$(echo $URL | sed 's#\/#/#g')
echo $URL

All that’s needed for this script are bash, curl, and sed, which should be present on any modern Unix-like system.

Here’s the output:

$ ~/Dropbox/bin/ ~/Desktop/leb_logo.png

That URL is now suitable for use on any forum.



I’m Andrew, techno polymath and long-time LowEndTalk community Moderator. My technical interests include all things Unix, perl, python, shell scripting, and relational database systems. I enjoy writing technical articles here on LowEndBox to help people get more out of their VPSes.