跳至正文
Wener Notes

tus

约 1 分钟阅读

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
http
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

bash
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

bash
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_FINISH
    • POST_RECEIVE_V2 - 每隔 postReceiveInterval 会调用一次,能够获取到进度
    • POST_FINISH - 上传完成,完成响应给客户端
    • POST_TERMINATE - 上传被终止,完成响应给客户端
  • KvStore
    • MemoryKvStore
    • FileKvStore
      • ./{KEY}.json
    • RedisKvStore
    • IoRedisKvStore
  • DataStore
    • FileStore
    • S3Store
bash
npm add @tus/server @tus/file-store @tus/s3-store
依赖包
TypeScript
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

关联信息

反向链接、本文链接的其他页面和外部资料。

反向链接

  • 存储服务常见问题
    笔记 · tus

    xfs,ext4 inode 通常在百万级别时会有性能问题 · 元数据管理、fsck、目录 list、碎片化 · Gmail attachment 20-25 MB · Google Driver · GitHub 50MB 警告,限制 100MB

参考资料

GitHub5 条
依赖包1 条
其他外链2 条
最近更新commit cf0d51a编辑