tus
约 1 分钟阅读
- tus
- tus.io/implementations.html
- SDK for JS, Java, iOS, Python, NodeJS, .NET
- tus v1 协议
- tus v2 被 httpwg 采用
- tus.io/implementations.html
- tus/tusdGitHubtus/tusdhttps://tus.io/implementations.html · SDK for JS, Java, iOS, Python, NodeJS, .NET · tus v1 协议 · tus v2 被 httpwg 采用 · https://github.com/httpwg/http-extensions/blob/main/draft-ie...笔记:tus
- MIT, Golang
- 支持暂停恢复
- 使用 hook 机制来实现业务逻辑
- shell, http, gRPC, golang plugin
- tus/tus-node-serverGitHubtus/tus-node-serverhttps://tus.io/implementations.html · SDK for JS, Java, iOS, Python, NodeJS, .NET · tus v1 协议 · tus v2 被 httpwg 采用 · https://github.com/httpwg/http-extensions/blob/main/draft-ie...笔记:tus
- NodeJS server
- @tus/server, @tus/file-store, @tus/s3-store
- 使用 EVENTS 来实现自定义逻辑
- 参考
- uppy
- tus/tus-js-clientGitHubtus/tus-js-client
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
- Upload-Offset
- 方法
- 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,crc32tusd
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=falsehooks
- Type
- script
- http
- gRPC
- golang plugin
- Hook
- pre-create
- post-create
- post-receive
- 默认未开启
- pre-finish
- post-finish
- post-terminate
- Model
tusd --hooks-http http://localhost:8081/write --hooks-http-retry 5 --hooks-http-backoff 2tus-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
npm add @tus/server @tus/file-store @tus/s3-store依赖包@tus/servernpm 包@tus/serverNPM@tus/file-storenpm 包@tus/file-storeNPM@tus/s3-storenpm 包@tus/s3-storeNPM
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 条
- httpwg/http-extensions/draft-ietf-httpbis-resumable-upload.mdgithub.com/httpwg/http-extensions/blob/main/draft-ietf-httpbis-resumable-upload.md
- tus/tus-js-clientgithub.com/tus/tus-js-client
- tus/tus-node-servergithub.com/tus/tus-node-server
- tus/tusdgithub.com/tus/tusd
- tus/tusd/docs/hooks.mdgithub.com/tus/tusd/blob/main/docs/hooks.md
依赖包1 条
- github.com/tus/tusd/v2/pkg/hookspkg.go.dev/github.com/tus/tusd/v2/pkg/hooks
其他外链2 条
- tus.io/implementations.htmltus.io/implementations.html
- tus.io/protocols/resumable-upload.htmltus.io/protocols/resumable-upload.html