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 URL2
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 file4
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
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
Max Size: 25MB
Use Case: Trade licenses, contracts, receipts
Videos
Formats: MP4, WebM, MOV
Max Size: 100MB
Use Case: Product demos, store tours
Max Size: 100MB
Use Case: Product demos, store tours
Audio
Formats: MP3, WAV, OGG
Max Size: 25MB
Use Case: Voice notes, audio descriptions
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
File Validation
File Validation
Always validate file types and sizes on the client side before uploading:
Upload URL Expiration
Upload URL Expiration
Upload URLs expire after 1 hour for security. Generate a new URL if upload fails:
Progress Tracking
Progress Tracking
Track upload progress for better user experience:
Error Handling
Upload URL generation failed
Upload URL generation failed
Status Code:
500File upload failed
File upload failed
Status Code:
400Invalid file type
Invalid file type
Status Code:
400Upload URLs are temporary and expire after 1 hour. Always generate a fresh URL for each upload operation.
