Upload Multiple Images

This tutorial explains how to upload more than one image within a single request.


For this tutorial you will need both the Python and requests libraries installed.


1. Initialize variables

Set the global variables.

import requests
API_DOMAIN = '<your-secure-domain>'
API_KEY = '<your-api-key>'

2. Read image files to upload

This code snippet reads the image files and prepares them to be in the type that is expected for the requests library.

image_filenames = [
image_files = []
for image_filename in image_filenames:
        ('file', (image_filename, open('/tmp/{}'.format(image_filename), 'rb'), 'image/png'))

3. Perform upload request

Finally, perform an upload request and print its ID and URL.

response = requests.post(
    params={'api_key': API_KEY},
image_api_response = response.json()
for image_info in image_api_response:
    print(image_info['id'], image_info['thumbnails']['origin'])