Expand description
TUS (Resumable Upload Protocol) implementation for the Salvo web framework.
TUS is an open protocol for resumable file uploads over HTTP. It allows reliable uploads of large files by enabling pause and resume functionality, making it ideal for unreliable network conditions.
§Features
- Resumable uploads - Clients can resume interrupted uploads
- Upload metadata - Attach custom metadata to uploads
- Configurable max size - Limit upload file sizes
- Lifecycle hooks - React to upload events
- Customizable storage - Implement your own storage backend
§Example
ⓘ
use salvo_tus::{Tus, MaxSize};
use salvo_core::prelude::*;
let tus = Tus::new()
.path("/uploads")
.max_size(MaxSize::Fixed(100 * 1024 * 1024)); // 100 MB limit
let router = Router::new()
.push(tus.into_router());
let acceptor = TcpListener::new("0.0.0.0:8080").bind().await;
Server::new(acceptor).serve(router).await;§TUS Protocol Endpoints
The router created by into_router() handles:
| Method | Path | Description |
|---|---|---|
| OPTIONS | /uploads | Returns TUS protocol capabilities |
| POST | /uploads | Creates a new upload |
| HEAD | /uploads/{id} | Returns upload progress |
| PATCH | /uploads/{id} | Uploads a chunk |
| DELETE | /uploads/{id} | Cancels an upload |
| GET | /uploads/{id} | Downloads the uploaded file |
§Lifecycle Hooks
React to upload events:
ⓘ
let tus = Tus::new()
.with_on_upload_create(|req, upload_info| async move {
println!("New upload: {:?}", upload_info);
Ok(UploadPatch::default())
})
.with_on_upload_finish(|req, upload_info| async move {
println!("Upload complete: {:?}", upload_info);
Ok(UploadFinishPatch::default())
});§Custom Upload ID
Generate custom upload IDs:
ⓘ
let tus = Tus::new()
.with_upload_id_naming_function(|req, metadata| async move {
Ok(uuid::Uuid::new_v4().to_string())
});§Storage Backends
By default, files are stored on disk using DiskStore.
Implement DataStore trait for custom storage (S3, database, etc.).
Read more: https://salvo.rs
Modules§
Structs§
Enums§
Constants§
- CT_
OFFSET_ OCTET_ STREAM - H_
ACCESS_ CONTROL_ ALLOW_ HEADERS - H_
ACCESS_ CONTROL_ ALLOW_ METHODS - H_
ACCESS_ CONTROL_ MAX_ AGE - H_
ACCESS_ CONTROL_ REQUEST_ HEADERS - H_
CONTENT_ LENGTH - H_
CONTENT_ TYPE - H_
TUS_ EXTENSION - H_
TUS_ MAX_ SIZE - H_
TUS_ RESUMABLE - H_
TUS_ VERSION - H_
UPLOAD_ CONCAT - H_
UPLOAD_ DEFER_ LENGTH - H_
UPLOAD_ EXPIRES - H_
UPLOAD_ LENGTH - H_
UPLOAD_ METADATA - H_
UPLOAD_ OFFSET - TUS_
VERSION