Tusflow

Resumable Uploads

Learn how Tusflow leverages Upstash Redis, AWS S3 multipart uploads, and the TUS protocol for efficient and reliable resumable file uploads.

Overview

Tusflow utilizes a powerful combination of Upstash Redis, AWS S3 multipart uploads, and the TUS protocol to provide a robust and efficient resumable upload solution.

Resumable uploads allow clients to pause and resume file uploads, making the process more resilient to network issues and providing a better user experience.

Key Components

Upstash Redis

A serverless Redis database used for storing upload metadata and managing upload state.

AWS S3 Multipart Uploads

Enables large file uploads to be split into smaller parts, uploaded independently, and then reassembled.

TUS Protocol

An open protocol for resumable file uploads, ensuring consistency and interoperability.

Features

Upstash Redis Integration

  • Serverless and globally distributed
  • Low-latency access to upload metadata
  • Automatic scaling and high availability

AWS S3 Multipart Upload

  • Support for large file uploads (up to 5TB)
  • Parallel upload of file parts
  • Ability to pause and resume uploads

TUS Protocol Implementation

  • Standardized resumable upload process
  • Cross-platform compatibility
  • Built-in error handling and recovery

How It Works

Understanding the upload process is crucial for optimizing your application's performance and reliability.

  1. Initiate Upload

    • Client sends a POST request with file metadata
    • Server creates an entry in Upstash Redis and initiates S3 multipart upload
  2. Upload Chunks

    • Client sends file chunks using PATCH requests
    • Server uploads parts to S3 and updates progress in Upstash Redis
  3. Resume Upload

    • Client can retrieve upload offset using HEAD request
    • Server fetches current state from Upstash Redis
  4. Complete Upload

    • After all chunks are uploaded, server completes S3 multipart upload
    • Upload metadata is cleaned up from Upstash Redis

Best Practices

  1. Optimal Chunk Size

    • Balance between network efficiency and memory usage
    • Typically between 5MB to 15MB per chunk
  2. Error Handling

    • Implement exponential backoff for retries
    • Handle network disconnections gracefully
  3. Progress Tracking

    • Utilize Upstash Redis for real-time progress updates
    • Implement client-side progress bars for better UX

Code Examples

POST /files HTTP/1.1
Host: api.tusflow.com
Tus-Resumable: 1.0.0
Upload-Length: 100000000
Upload-Metadata: filename d29ya2Zsb3cuanBn,mimetype aW1hZ2UvanBlZw==
 
HTTP/1.1 201 Created
Location: https://<your-workers-endpoint>/files/24e533e02ec3bc40c387f1a0e460e216
Tus-Resumable: 1.0.0

By leveraging Upstash Redis, AWS S3 multipart uploads, and the TUS protocol, Tusflow provides a powerful and flexible resumable upload solution that can handle large files, network interruptions, and high concurrency with ease.

Edit on GitHub

Last updated on

On this page