File Upload Guide

Step-by-step guide for uploading files using the pre-signed URL pattern.

This guide explains how to upload files using the Files API's pre-signed URL pattern. The upload process consists of two steps: getting a pre-signed URL from the API, then uploading directly to S3 storage.

Overview

The file upload process is designed for security and scalability:

  1. API Request: Get a pre-signed URL and upload parameters
  2. Direct Upload: Upload file directly to S3 using the provided URL
  3. Verification: File is automatically processed and available for use

Step 1: Get Upload URL

First, request a pre-signed URL from the API with your file metadata:

Request

curl -X POST https://api.authvia.com/v3/accounts/{account-id}/files \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "fileName": "invoice_2024_001.pdf",
    "contentType": "application/pdf",
    "description": "Invoice for customer CUST001",
    "businessProcess": "payment-processing",
    "businessProcessAction": "document-upload",
    "expiration": "30d"
  }'

Required Fields

FieldTypeRequiredDescriptionExample
fileNamestringName of the file to uploadinvoice.pdf
contentTypestringMIME type of the fileapplication/pdf

Optional Fields

FieldTypeDescriptionExample
descriptionstringHuman-readable descriptionInvoice for customer CUST001
businessProcessstringAssociated business processpayment-processing
businessProcessActionstringSpecific action within processdocument-upload
expirationstringFile expiration time30d, 5h, 60m

Response

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "uploadUrl": "https://s3.amazonaws.com/bucket/presigned-url",
  "fields": {
    "key": "files/550e8400-e29b-41d4-a716-446655440000",
    "bucket": "authvia-files",
    "X-Amz-Algorithm": "AWS4-HMAC-SHA256",
    "X-Amz-Credential": "AKIA...",
    "X-Amz-Date": "20240115T103000Z",
    "Policy": "eyJleHBpcmF0aW9uIjoiMjAyNC0wMS0xNVQxMDozNTowMFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJhdXRodmlhLWZpbGVzIn0sWyJzdGFydHMtd2l0aCIsIiRrZXkiLCJmaWxlcy8iXV19",
    "X-Amz-Signature": "abc123..."
  }
}

Step 2: Upload to S3

Use the pre-signed URL and fields to upload your file directly to S3:

Using cURL

curl -X POST "https://s3.amazonaws.com/bucket/presigned-url" \
  -F "key=files/550e8400-e29b-41d4-a716-446655440000" \
  -F "bucket=authvia-files" \
  -F "X-Amz-Algorithm=AWS4-HMAC-SHA256" \
  -F "X-Amz-Credential=AKIA..." \
  -F "X-Amz-Date=20240115T103000Z" \
  -F "Policy=eyJleHBpcmF0aW9uIjoiMjAyNC0wMS0xNVQxMDozNTowMFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJhdXRodmlhLWZpbGVzIn0sWyJzdGFydHMtd2l0aCIsIiRrZXkiLCJmaWxlcy8iXV19" \
  -F "X-Amz-Signature=abc123..." \
  -F "[email protected]"

Content Type Validation

The API enforces strict content type validation. File extensions must match the content type:

Content TypeValid ExtensionsExample
application/pdf.pdfinvoice.pdf
text/plain.txt, .textreport.txt
image/png.pnglogo.png
image/jpeg.jpg, .jpegphoto.jpg
image/webp.webpimage.webp
image/bmp.bmpimage.bmp
image/tiff.tiff, .tifscan.tiff
⚠️

Important: If the file extension doesn't match the content type, the API will return a validation error.

File Expiration

Files can have configurable expiration times:

  • Format: {number}{unit} where unit is h (hours), d (days), or m (minutes)
  • Default: 60d (60 days) if not specified
  • Examples: 5h, 10d, 30m
{
  "fileName": "temporary_report.pdf",
  "contentType": "application/pdf",
  "expiration": "5h"  // Expires in 5 hours
}

Error Handling

Common Errors

Error CodeDescriptionResolution
INVALID_CONTENT_TYPEContent type doesn't match file extensionEnsure file extension matches content type
FILE_TOO_LARGEFile exceeds size limitReduce file size or contact support
INVALID_EXPIRATIONInvalid expiration formatUse format like 30d, 5h, 60m
MISSING_FIELDSRequired fields missingInclude fileName and contentType
UNAUTHORIZEDInvalid or missing authenticationCheck your API token
FORBIDDENInsufficient permissionsVerify account access

S3 Upload Errors

ErrorDescriptionResolution
Access DeniedPre-signed URL expired or invalidGet a new upload URL
Entity Too LargeFile exceeds S3 limitsReduce file size
Network ErrorConnection issuesRetry the upload