Instant upload images to imgur from android

Python needs to be embraced for it's capacity to gel with android so well and make things easier with simple and fun scripts.

After installing G+ android app, /me was curious about instant upload of images that the app provides, so decided to make a simple script to emulate the same, but as imgur is one my favs, used the same.

Instant upload images to imgur is a simple script that does :

  • Invoke camera to take a picture.
  • Upload the picture to imgur.
  • SMS the link to the img.
  • Copies the link to the cilpboard.
  • Open the img url in the default browser.

P.S : Additionally sending email, creating QR code and much more can be done with the img url.

The code below works fine, once you assign a number the SMS_TO variable and suggest to use your own API key from imgur.

""" Instanly upload to IMGUR, SMS, copies to clip and opens the img URL """
import android
from json import loads as json_decode
from urllib2 import Request, urlopen
from urllib import urlencode
import base64

__author__ = 'Hemanth H.M <[email protected]>'
__copyright__ = 'Copyright (c) 2010,'
__license__ = 'GNU GPLv3'

""" The API_URL, API_KEY and IMG_APTH. """
URL = ''
""" Please change the key to your key """
API_KEY = '6999d11def1e31418e8eaea7cae66761'
IMG_PATH = '/sdcard/imgur.jpg'

""" Number to which the link must be texted """

droid = android.Android()
""" Invoke camrea to capture picture and save it to IMG_PATH """

    with file(IMG_PATH,'rb') as pic:
        droid.dialogCreateSpinnerProgress("Uploading","Please wait...")
        image =
        post = {
            'key': API_KEY,
            'image': base64.b64encode(image),
            'path': IMG_PATH

        data = urlencode(post)
            img_url = urlopen(Request(URL, data))
        except Exception, e:

        response = json_decode(

        link = response['upload']['links']['original']
        droid.dialogCreateAlert("Uploaded,Sms'd, copied to clipboard, now view the link!");
except IOError:
    droid.dialogCreateAlert("Sorry could not find the image!");

If this was fun, have a look at Sending Random jokes from android

Share this