Skip to main content

Overview

The Utilities API provides essential system functions including secure file upload URL generation and other utility operations needed across the platform. Location: convex/shared/utils.ts

Generate Upload URL

Generates a secure upload URL for file uploads to Convex storage.

File Upload Process

The file upload process follows these steps:
1

Generate Upload URL

Call generateUploadUrl to get a secure, temporary upload URL
2

Upload File

Use the returned URL to upload your file via HTTP POST
3

Get Storage ID

The upload response contains a storageId that you can use to reference the file
4

Use Storage ID

Use the storageId in other API calls (e.g., creating products with images)

Supported File Types

Images

Formats: JPEG, PNG, WebP, GIF, SVG
Max Size: 10MB
Recommended: WebP for web, PNG for transparency

Documents

Formats: PDF, DOC, DOCX, TXT
Max Size: 25MB
Use Case: Trade licenses, contracts, receipts

Videos

Formats: MP4, WebM, MOV
Max Size: 100MB
Use Case: Product demos, store tours

Audio

Formats: MP3, WAV, OGG
Max Size: 25MB
Use Case: Voice notes, audio descriptions

Complete Upload Example

Here’s a complete example showing how to upload a file and use it:

Security & Best Practices

Always validate file types and sizes on the client side before uploading:
Upload URLs expire after 1 hour for security. Generate a new URL if upload fails:
Track upload progress for better user experience:

Error Handling

Status Code: 500
Status Code: 400
Status Code: 400
Upload URLs are temporary and expire after 1 hour. Always generate a fresh URL for each upload operation.
For better performance, compress images before uploading and use WebP format when possible for web applications.