STORE API Endpoint

Version 2.197 (Release Notes ↗)

Description

Upload local media files, including videos and images, to the PixLab storage cluster or your connected S3 Bucket. This API endpoint, STORE, is essential for initiating processing tasks like mogrify, merge, and drawlines, ensuring media files are remotely available for seamless handling.

Upload a local media file whether video or image to the pixlab.xyz storage cluster or to your own S3 Bucket if already connected from your dashboard ↗. This API endpoint is always the first step for some processing tasks like mogrify, merge, drawlines, etc. that require a media file to be remotely available before processing it.

HTTP Methods

POST

HTTP Parameters

POST Request Body

Allowed Content-Type:
multipart/form-data

Required

Fields Type Description
key String Your PixLab API Key ↗. You can also embed your key in the WWW-Authenticate: HTTP header and omit this parameter if you want to.

Optional Parameters

Fields Type Description
comment String Optional comment to associate with the uploaded media.

HTTP Response

Fields Type Description
status Integer Status code 200 indicates success, any other code indicates failure.
link URL Link to the media output which is usually stored on the pixlab.xyz storage cluster unless you set your own S3 keys (refer to your dashboard ↗ on how to do that).
id String Unique media ID.
error String Error message if status != 200.

Code Samples


import requests
from typing import Dict, Any

def upload_image(image_path: str, api_key: str, comment: str = "") -> str:
    """Upload a local image to PixLab storage server.
    
    Args:
        image_path: Path to the local image file.
        api_key: Your PixLab API key.
        comment: Optional comment for the uploaded image.
    
    Returns:
        The URL of the uploaded image.
    
    Raises:
        requests.exceptions.RequestException: If the upload fails.
        ValueError: If the API response indicates an error.
    """
    try:
        with open(image_path, 'rb') as image_file:
            response = requests.post(
                'https://api.pixlab.io/store',
                files={'file': image_file},
                data={
                    'comment': comment,
                    'key': api_key,
                },
                timeout=30
            )
            response.raise_for_status()
            data: Dict[str, Any] = response.json()
            
            if data.get('status') != 200:
                raise ValueError(data.get('error', 'Unknown error occurred'))
            
            return data['link']
    
    except FileNotFoundError as e:
        raise FileNotFoundError(f"Image file not found: {image_path}") from e

# Example usage:
if __name__ == "__main__":
    try:
        image_url = upload_image(
            image_path='./local_image.png',
            api_key='My_PIXLAB_API_KEY',
            comment='Super Secret Stuff'
        )
        print(f"Uploaded image link: {image_url}")
    except Exception as e:
        print(f"Error uploading image: {e}")
← Return to API Endpoint Listing