Skip to main content
Using Sevalla’s object storage, powered by Cloudflare R2, with your JavaScript or TypeScript application provides secure, scalable, and persistent storage for files such as images, videos, documents, or application-generated assets. Its S3-compatible API allows seamless integration with popular JS/TS libraries, enabling easy programmatic access for uploads, downloads, and file management. This makes it ideal for handling user uploads, storing backend outputs, caching media, or serving assets to your frontend, all while keeping your data private and reliably accessible across deployments and application instances. We recommend using the AWS S3 SDK for object storage, file uploads, and asset management in JavaScript/TypeScript applications.

Installation

Install the required dependencies:
  • @aws-sdk/client-s3: AWS SDK v3 for S3 operations (modular and tree-shakeable).
Optional for advanced features:

Environment variables

Add the following environment variables to your application from the Object storage service details:

Setting up the client

Note: AWS SDK v3 uses modular imports, which means you only import the commands you need, resulting in smaller bundle sizes.

Basic usage examples

Upload a file

Download a file

Delete a file

List files in bucket

Generate pre-signed URL (Temporary access)

Advanced S3 operations

Multi-part upload (Large files)

Copy objects

Get object metadata

Set object ACL (Access control)

Best Practices

  1. Use streaming for large files - Don’t load entire files into memory
  2. Implement retry logic - S3 operations can fail, implement exponential backoff
  3. Use pre-signed URLs - For direct client uploads/downloads, reduce server load
  4. Set appropriate CORS - Configure bucket CORS if accessing from browser
  5. Use multipart upload - For files > 100MB
  6. Implement file validation - Check file types and sizes before upload
  7. Use proper naming conventions - Organize files with prefixes (folders)
  8. Enable versioning - For important files, enable S3 versioning
  9. Monitor storage costs - Use lifecycle policies to move/delete old files
  10. Implement error handling - Always wrap S3 operations in try-catch blocks
  11. Use content types - Always set the correct ContentType when uploading
  12. Secure credentials - Never commit S3 credentials, use environment variables

Common Issues

Access Denied Errors

If you get “Access Denied” errors:
  • Verify access key and secret key are correct
  • Verify the bucket policy allows the operations
  • Ensure credentials match the service details

Connection Timeout

If uploads/downloads timeout:
  • Verify S3_ENDPOINT is correct
  • Increase timeout in S3 client config:

Large File Upload Issues

For large files:
  • Use multipart upload for files > 100MB
  • Implement progress tracking
  • Handle network interruptions with retry logic

CORS Errors (Browser Uploads)

Fine-tune your bucket CORS configuration on the Sevalla dashboard.

Performance Tips

  1. Parallelize uploads:
  2. Cache frequently accessed files:
  3. Implement pagination for listing:

Security Best Practices

  1. Enable encryption at rest - Use server-side encryption:
  2. Scan files for viruses before storing
  3. Implement rate limiting for upload endpoints
  4. Validate file types based on content, not just extension
  5. Use signed URLs for sensitive content