# Multipart uploads

Upload a large file in parts, complete the storage upload with ordered ETags, and register its source URL.

URL: /guides/uploads/multipart-upload



Use multipart upload when a file is too large for a single transfer or individual parts need to be retried.

## 1. Create the upload [#1-create-the-upload]

```bash
export LINGOPAL_API_KEY="your-api-key"

curl -X POST "https://api.lingopal.ai/v2/storage/uploads" \
  -H "X-API-Key: $LINGOPAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "file_ext": "mp4",
    "file_size": 2147483648
  }'
```

## POST /v2/storage/uploads

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Create a presigned storage upload",
    "description": "Lingopal v2 public API for text translation, storage uploads, registered jobs, job workflows, and job outputs.",
    "version": "v2"
  },
  "servers": [
    {
      "url": "https://vod-api.lingopal-dev.com"
    }
  ],
  "security": [
    {
      "APIKeyHeader": []
    }
  ],
  "paths": {
    "/v2/storage/uploads": {
      "post": {
        "tags": [
          "Storage"
        ],
        "summary": "Create a presigned storage upload",
        "description": "Returns one or more presigned S3 upload URLs for uploading a source file before registering it with `/v2/jobs/register`. Provide `file_size` to request a multipart upload.",
        "operationId": "createStorageUpload",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StorageUploadRequest"
              },
              "examples": {
                "singlePartStorageUpload": {
                  "summary": "Create a single-part upload URL",
                  "description": "Request one presigned PUT URL for a client-managed source upload. Register the returned source_url later with `/v2/jobs/register`.",
                  "value": {
                    "file_ext": "mp4"
                  }
                },
                "multipartStorageUpload": {
                  "summary": "Create multipart upload URLs",
                  "description": "Request presigned part URLs for a large source upload. Complete the multipart upload with `/v2/storage/uploads/complete`, then register the returned source_url with `/v2/jobs/register`.",
                  "value": {
                    "file_ext": "mp4",
                    "file_size": 524288000
                  }
                }
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Presigned upload metadata and upload part URLs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StorageUploadResponse"
                },
                "example": {
                  "source_url": "https://cdn.example.com/presigned_upload/user_123/source.mp4",
                  "file_path": "presigned_upload/user_123/source.mp4",
                  "upload_id": "2~example-upload-id",
                  "upload_urls": [
                    {
                      "part_number": 1,
                      "upload_url": "https://example-bucket.s3.amazonaws.com/presigned_upload/user_123/source.mp4?partNumber=1&X-Amz-Signature=..."
                    }
                  ],
                  "method": "PUT",
                  "headers": {
                    "Content-Type": "video/mp4"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid authentication token."
          },
          "422": {
            "description": "Request validation error."
          }
        },
        "security": [
          {
            "APIKeyHeader": []
          }
        ]
      }
    }
  },
  "tags": [
    {
      "name": "Storage",
      "description": "Create and complete presigned storage uploads for source files."
    }
  ],
  "components": {
    "schemas": {
      "StorageUploadRequest": {
        "properties": {
          "file_ext": {
            "type": "string",
            "minLength": 1,
            "title": "File Ext",
            "description": "Source file extension, with or without a leading dot.",
            "examples": [
              "mp4",
              "wav",
              "pdf"
            ]
          },
          "file_size": {
            "anyOf": [
              {
                "type": "integer",
                "exclusiveMinimum": 0
              },
              {
                "type": "null"
              }
            ],
            "title": "File Size",
            "description": "Source file size in bytes. Provide this value to request multipart presigned upload URLs; omit it for a single PUT upload URL.",
            "examples": [
              104857600
            ]
          }
        },
        "type": "object",
        "required": [
          "file_ext"
        ],
        "title": "StorageUploadRequest"
      },
      "StorageUploadResponse": {
        "properties": {
          "source_url": {
            "type": "string",
            "title": "Source Url",
            "description": "Final URL of the uploaded file after upload completion.",
            "examples": [
              "https://example-bucket.s3.amazonaws.com/presigned_upload/user/file.mp4"
            ]
          },
          "file_path": {
            "type": "string",
            "title": "File Path",
            "description": "Storage path for the storage upload. Use this when completing multipart uploads.",
            "examples": [
              "presigned_upload/user_123/source.mp4"
            ]
          },
          "upload_id": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Upload Id",
            "description": "S3 multipart upload ID. Present only when the storage upload uses multipart upload.",
            "examples": [
              "2~example-upload-id"
            ]
          },
          "upload_urls": {
            "items": {
              "$ref": "#/components/schemas/UploadPart"
            },
            "type": "array",
            "title": "Upload Urls",
            "description": "Presigned upload URLs, one per upload part."
          },
          "method": {
            "type": "string",
            "const": "PUT",
            "title": "Method",
            "description": "HTTP method clients must use for each presigned upload URL.",
            "default": "PUT"
          },
          "headers": {
            "additionalProperties": {
              "type": "string"
            },
            "type": "object",
            "title": "Headers",
            "description": "Additional headers clients should send with the upload request.",
            "examples": [
              {}
            ]
          }
        },
        "type": "object",
        "required": [
          "source_url",
          "file_path"
        ],
        "title": "StorageUploadResponse",
        "examples": [
          {
            "file_path": "presigned_upload/user_123/source.mp4",
            "headers": {
              "Content-Type": "video/mp4"
            },
            "method": "PUT",
            "source_url": "https://cdn.example.com/presigned_upload/user_123/source.mp4",
            "upload_id": "2~example-upload-id",
            "upload_urls": [
              {
                "part_number": 1,
                "upload_url": "https://example-bucket.s3.amazonaws.com/presigned_upload/user_123/source.mp4?partNumber=1&X-Amz-Signature=..."
              }
            ]
          }
        ]
      },
      "UploadPart": {
        "properties": {
          "part_number": {
            "type": "integer",
            "title": "Part Number",
            "description": "One-based multipart upload part number.",
            "examples": [
              1
            ]
          },
          "upload_url": {
            "type": "string",
            "title": "Upload Url",
            "description": "Presigned URL used to upload this part with the documented HTTP method.",
            "examples": [
              "https://example-bucket.s3.amazonaws.com/presigned_upload/user/file.mp4?X-Amz-Signature=..."
            ]
          }
        },
        "type": "object",
        "required": [
          "part_number",
          "upload_url"
        ],
        "title": "UploadPart"
      }
    },
    "securitySchemes": {
      "APIKeyHeader": {
        "in": "header",
        "name": "X-API-Key",
        "type": "apiKey"
      }
    }
  }
}
```

Use the [API Reference entry for createStorageUpload](/reference/storage/createStorageUpload) for exact request payload and response fields.

Save `file_path`, `upload_id`, `source_url`, and every item in `upload_urls`.

## 2. Upload every part [#2-upload-every-part]

PUT each byte range to its corresponding presigned URL. Record the returned ETag and part number. Failed parts can be retried independently while their presigned URLs remain valid.

## 3. Complete the upload [#3-complete-the-upload]

Send the saved `file_path`, `upload_id`, and ETags in part order:

```bash
export LINGOPAL_API_KEY="your-api-key"

curl -X POST "https://api.lingopal.ai/v2/storage/uploads/complete" \
  -H "X-API-Key: $LINGOPAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "file_path": "presigned_upload/user/source.mp4",
  "upload_id": "upload-id",
  "etags": [
    {"part_number": 1, "etag": "etag-1"},
    {"part_number": 2, "etag": "etag-2"}
  ]
}'
```

## POST /v2/storage/uploads/complete

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Complete a multipart storage upload",
    "description": "Lingopal v2 public API for text translation, storage uploads, registered jobs, job workflows, and job outputs.",
    "version": "v2"
  },
  "servers": [
    {
      "url": "https://vod-api.lingopal-dev.com"
    }
  ],
  "security": [
    {
      "APIKeyHeader": []
    }
  ],
  "paths": {
    "/v2/storage/uploads/complete": {
      "post": {
        "tags": [
          "Storage"
        ],
        "summary": "Complete a multipart storage upload",
        "description": "Completes an S3 multipart upload created by `/v2/storage/uploads`. Only uploads owned by the authenticated user can be completed.",
        "operationId": "completeStorageUpload",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompleteStorageUploadRequest"
              },
              "examples": {
                "completeMultipartStorageUpload": {
                  "summary": "Complete multipart source upload",
                  "description": "Finalize a multipart upload after every part has been uploaded to S3. Then register the returned source_url with `/v2/jobs/register`.",
                  "value": {
                    "file_path": "presigned_upload/user_123/source.mp4",
                    "upload_id": "2~example-upload-id",
                    "etags": [
                      {
                        "part_number": 1,
                        "etag": "\"9b2cf535f27731c974343645a3985328\""
                      },
                      {
                        "part_number": 2,
                        "etag": "\"2a1fd1f7bc39b3868d2a8f6fb50f6a7d\""
                      }
                    ]
                  }
                }
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Completed storage upload location.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompleteStorageUploadResponse"
                },
                "example": {
                  "file_path": "presigned_upload/user_123/source.mp4",
                  "source_url": "https://cdn.example.com/presigned_upload/user_123/source.mp4"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid authentication token."
          },
          "403": {
            "description": "The authenticated user cannot access this resource."
          },
          "422": {
            "description": "Request validation error."
          }
        },
        "security": [
          {
            "APIKeyHeader": []
          }
        ]
      }
    }
  },
  "tags": [
    {
      "name": "Storage",
      "description": "Create and complete presigned storage uploads for source files."
    }
  ],
  "components": {
    "schemas": {
      "CompleteStorageUploadRequest": {
        "properties": {
          "file_path": {
            "type": "string",
            "title": "File Path",
            "description": "Storage path returned by `/v2/storage/uploads` for the multipart upload.",
            "examples": [
              "presigned_upload/user_123/source.mp4"
            ]
          },
          "upload_id": {
            "type": "string",
            "title": "Upload Id",
            "description": "Multipart upload ID returned by `/v2/storage/uploads`.",
            "examples": [
              "2~example-upload-id"
            ]
          },
          "etags": {
            "items": {
              "anyOf": [
                {
                  "$ref": "#/components/schemas/CompletedUploadPart"
                },
                {
                  "type": "string"
                }
              ]
            },
            "type": "array",
            "minItems": 1,
            "title": "Etags",
            "description": "ETags for uploaded parts, ordered by part number. String ETags are accepted for compatibility."
          }
        },
        "type": "object",
        "required": [
          "file_path",
          "upload_id",
          "etags"
        ],
        "title": "CompleteStorageUploadRequest"
      },
      "CompleteStorageUploadResponse": {
        "properties": {
          "file_path": {
            "type": "string",
            "title": "File Path",
            "description": "Storage path for the completed storage upload.",
            "examples": [
              "presigned_upload/user_123/source.mp4"
            ]
          },
          "source_url": {
            "type": "string",
            "title": "Source Url",
            "description": "Final URL of the completed uploaded file.",
            "examples": [
              "https://example-bucket.s3.amazonaws.com/presigned_upload/user_123/source.mp4"
            ]
          }
        },
        "type": "object",
        "required": [
          "file_path",
          "source_url"
        ],
        "title": "CompleteStorageUploadResponse",
        "examples": [
          {
            "file_path": "presigned_upload/user_123/source.mp4",
            "source_url": "https://cdn.example.com/presigned_upload/user_123/source.mp4"
          }
        ]
      },
      "CompletedUploadPart": {
        "properties": {
          "part_number": {
            "type": "integer",
            "exclusiveMinimum": 0,
            "title": "Part Number",
            "description": "One-based part number returned by the storage upload response.",
            "examples": [
              1
            ]
          },
          "etag": {
            "type": "string",
            "title": "Etag",
            "description": "ETag returned by S3 after uploading this part.",
            "examples": [
              "\"9b2cf535f27731c974343645a3985328\""
            ]
          }
        },
        "type": "object",
        "required": [
          "part_number",
          "etag"
        ],
        "title": "CompletedUploadPart"
      }
    },
    "securitySchemes": {
      "APIKeyHeader": {
        "in": "header",
        "name": "X-API-Key",
        "type": "apiKey"
      }
    }
  }
}
```

Use the [API Reference entry for completeStorageUpload](/reference/storage/completeStorageUpload) for response and validation details.

## 4. Register the source [#4-register-the-source]

Register the `source_url` with `POST /v2/jobs/register` to receive a `job_id`. Storage completion alone does not start processing.
