:external option in allow_upload/3.
This guide continues from the configuration in the server Uploads guide.
Overview
External uploads work by:- Server generates pre-signed URL or upload metadata
- Client receives metadata via the
:externalcallback - JavaScript uploader sends files directly to cloud provider
- Progress and completion reported back to LiveView
Chunked HTTP Uploads (UpChunk)
For services supporting chunked uploads withContent-Range headers, use the UpChunk library.
1. Install UpChunk
- NPM
- Manual
2. Configure Upload on Server
3. Setup Client Uploader
Direct to S3
For uploads up to 5 GB, use direct S3 PUT/POST requests.Prerequisites
- S3 Information
- CORS Configuration
- AWS Access Key ID
- AWS Secret Access Key
- Bucket Name
- Region
1. Server-Side Presigning
2. Client-Side Uploader
Createassets/js/uploaders.js:
3. Wire Up in app.js
The
uploader key in the metadata (“S3”) must match the uploader name in your JavaScript object.S3-Compatible Services (PUT)
For services like Cloudflare R2 that don’t support POST multipart uploads:Server-Side (with ExAws)
Client-Side PUT Uploader
Entry and Uploader API
Entry Object
Provided to uploader functions:Uploader Function Signature
Complete Example: Google Cloud Storage
Debugging
Client-Side
- Check browser console for JavaScript errors
- Inspect Network tab for failed upload requests
- Verify CORS configuration allows your domain
Server-Side
Common Issues
- CORS Errors
- Signature Errors
- Progress Stalls
Problem: Browser blocks upload due to CORSSolution: Update bucket CORS configuration:
Best Practices
- Validate on server - Always validate file size and type server-side
- Set expiration - Use short-lived pre-signed URLs (1-2 hours)
- Handle errors - Provide clear error messages to users
- Progress feedback - Always show upload progress
- Cleanup - Abort uploads on view errors with
onViewError - Security - Never expose AWS credentials to the client
See Also
- Server Uploads Guide
- JS Interop - Client hooks and JavaScript integration
- Form Bindings - File input handling
- SimpleS3Upload Gist