Compressor APIRequestsFile Upload

File Upload

The File Upload endpoint allows you to send raw binary data directly to the Compressor API. This method is ideal when processing files that originate from user uploads, local file systems, background jobs, or any environment where the file is already in memory or on disk.

POST https://api.compressor.app/1.0/upload

The request must use multipart/form-data and include two fields:

FieldDescription
fileThe binary content of the file to compress or transform. This may be an image, video, document, archive, audio file, or any supported format.
dataA serialized JSON object describing the compression settings, format conversions, resizing instructions, metadata extraction options, or any additional operations to apply.

The file part must contain the actual binary payload. The data part is used for all processing parameters and must be valid JSON.

When to Use File Upload

Use the Upload endpoint when:

  • You are receiving user-generated uploads in your application
  • Your server already has the file stored locally
  • You prefer to avoid exposing files via public URLs
  • You need deterministic, controlled transfer without relying on remote fetches
TIP

For remote files (CDN assets, existing S3 objects, etc.), the File Fetch method is usually faster and more resource efficient.

Example Request

Here is a minimal example of uploading a file along with processing parameters:

curl https://api.compressor.app/1.0/upload \
  -X POST \
  -u your-api-key: \
  -F "file=@/path/to/input.jpg" \
  -F 'data={
    "image": {
      "resize": {
        "width": 640,
        "height": 480,
        "mode": "fit"
      }
    }
  }'

The same structure applies to any supported file type. For example, you can upload videos, PDFs, ZIP archives, audio files, or full website bundles — just adjust the JSON payload accordingly.

Notes & Best Practices

  • Always send the request using multipart/form-data
  • Ensure your JSON in data is properly escaped when using shell environments
  • The Upload endpoint respects all rate limits and authentication rules described earlier
  • For very large files or long-running operations, you may experience automatic fallback to asynchronous processing
On this page