How to Upload Multiple Files to pdfRest with cURL

Learn how to upload several files in one cURL multipart request and preserve their returned resource IDs for later processing.
Share this page

Follow this cURL walkthrough to upload multiple files to pdfRest with the Upload Files API Tool. Along the way, you'll learn which parts are ordinary cURL syntax, which fields are needed to upload multiple files to pdfRest, and what to expect from the API response.

Why Upload Multiple Files to pdfRest with cURL?

Batch and document-assembly workflows often need several resources before processing can begin. One multipart upload can stage all of those inputs and return the IDs used by later merge, attachment, or conversion calls.

For instance, a case-management job might upload a signed agreement, supporting image, and data file together. The application can retain the filename-to-ID mapping and then choose the correct resource for each subsequent API Tool.

The request repeats the same file field once per local input. cURL creates one multipart body, and the response contains a files entry for every accepted upload.

cURL Code Example

# By default, we use the US-based API service. This is the primary endpoint for global use.
API_URL="https://api.pdfrest.com"

# For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below.
# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work
# API_URL="https://eu-api.pdfrest.com"

curl -X POST "$API_URL/upload" \
  -H "Accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
  -F "file=@/path/to/file" \
  -F "file=@/path/to/file" \
  -F "file=@/path/to/file" \

Source for Upload Multiple to pdfRest: View the cURL sample on GitHub.

Breaking Down the Code

Choose the pdfRest service region

# By default, we use the US-based API service. This is the primary endpoint for global use.
API_URL="https://api.pdfrest.com"

# For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below.
# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work
# API_URL="https://eu-api.pdfrest.com"

The service URL is kept in one variable so the request can use either the US or EU pdfRest environment without changing the remaining command.

Start an authenticated multipart upload

curl -X POST "$API_URL/upload" \
  -H "Accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \

The request posts to /upload, asks for JSON, explicitly declares multipart form data, and supplies the placeholder API key used for authentication.

Add every local file as its own multipart part

-F "file=@/path/to/file" \
  -F "file=@/path/to/file" \
  -F "file=@/path/to/file" \

Each -F "file=@..." argument adds another binary file part. Repeating the field name is intentional and differs from sending a comma-separated list of paths.

Interpret the upload response

curl -X POST "$API_URL/upload"

A successful response contains a files array with resource IDs and file details. Preserve the association between each local filename and its returned ID before starting later operations.

Beyond the Tutorial

After completing the example, you can stage several files with one cURL request and carry their resource IDs into a larger document workflow.

Do not rely on array position after the response leaves the upload layer. Store each returned filename and ID together, confirm that every expected file was accepted, and clean up the resources when the workflow is complete.

Continue exploring the Upload Multiple to pdfRest workflow in API Lab. For the complete Upload Multiple to pdfRest request contract, accepted values, defaults, and limitations, consult the Upload Files API Tool documentation.

Generate a self-service API Key now!
Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.