Skip to main content

tus

Protocol

    • Upload-Offset
      • 当前
    • Upload-Length
      • 整体大小
    • Tus-Version
      • 1.0.0
    • Tus-Resumable
      • OPTIONS 需要包含
      • 值为版本号
      • 如果版本不支持返回 412 Precondition Failed
    • Tus-Extension
      • 服务端返回,逗号分隔
    • Tus-Max-Size
      • 服务端返回
      • 最大文件大小
    • X-HTTP-Method-Override
    • Upload-Defer-Length
    • Upload-Metadata
    • Tus-Checksum-Algorithm
    • Upload-Checksum
  • 方法
    • HEAD
    • PATCH
    • OPTIONS
    • 创建上传资源
      • -> POST /files
        • Upload-Length
        • Upload-Metadata
        • Tus-Resumable
      • <- 201 Created
        • Location
        • Tus-Resumable
OPTIONS /files HTTP/1.1
Host: tus.example.org

HTTP/1.1 204 No Content
Tus-Resumable: 1.0.0
Tus-Version: 1.0.0
Tus-Extension: checksum
Tus-Checksum-Algorithm: md5,sha1,crc32

tusd

tusd -upload-dir=./data

export AWS_ACCESS_KEY_ID=xxxxx
export AWS_SECRET_ACCESS_KEY=xxxxx
export AWS_REGION=eu-west-1
tusd -s3-bucket=my-test-bucket.com -s3-endpoint=minio -s3-object-prefix=upload -show-greeting=false

hooks

tusd --hooks-http http://localhost:8081/write --hooks-http-retry 5 --hooks-http-backoff 2

tus-node-server

  • 事件
    • POST_CREATE - 创建了 upload 但还没写入到 store
    • POST_RECEIVE
    • POST_RECEIVE_V2 - 每隔 postReceiveInterval 会调用一次,能够获取到进度
    • POST_FINISH - 上传完成,完成响应给客户端
    • POST_TERMINATE - 上传被终止,完成响应给客户端
npm add @tus/server @tus/file-store @tus/s3-store
type TUpload = {
id: string;
size?: number;
offset: number;
// uppy type, relativePath, name
// tusd filetype, filename
metadata?: Record<string, string | null>;
storage?: {
type: string;
path: string;
bucket?: string;
};
creation_date?: string;
};

extensions

  • creation
  • creation-with-upload
  • creation-defer-length
  • termination
  • expiration