# 前言

tusd 是 tus
可恢复上传协议的官方参考实现。该协议指定了一种使用 HTTP 将文件上传到远程服务器的灵活方法。
其特殊功能是能够随时暂停和恢复上传,从而可以在网络中断等情况下无缝继续。
它能够接受任意大小的上传,并将其存储在本地磁盘、Google Cloud Storage 或 AWS S3(或任何其他兼容 S3 的存储系统)上。由于其模块化和可扩展性,tusd 可以轻松添加对几乎任何其他云提供商的支持。

# Doker 部署

创建目录并进入

mkdir tusd && cd tusd

执行 docker 命令 或 复制下面内容到 start.sh 文件,执行 sh start.sh
tusd 自定义配置 如: -max-size=209715200 最大上传 200M

docker run -d --user 0:0 \
    --restart=always \
    --name=tus \
    --privileged=true \
    -v $(pwd)/data/:/srv/tusd-data/data/:rw \
    -p 8080:8080 \
    tusproject/tusd:latest -max-size=209715200

# 客户端

多种使用方法
例子 tus-js-client

const upload = new tus.Upload(file, {
  // Replace this with tusd's upload creation URL
  endpoint: 'http://localhost:8080/files/',
  onError: function (error) {
    console.log('Failed because: ' + error)
  },
  onSuccess: function () {
    console.log('Download %s from %s', upload.file.name, upload.url)
  },
})
upload.start()

# Nginx https + 反代

配置参考

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        listen 443 http2 ssl;
        listen [::]:443 http2 ipv6only=on ssl;
        ssl_certificate         /data/letsencrypt/fullchain.crt;
        ssl_certificate_key     /data/letsencrypt/private.pem;
        #ssl_trusted_certificate /data/letsencrypt/certificate.crt;
        # Load custom parameters for Diffie Hellman key exchange to avoid the usage
        # of common primes
        # ssl_dhparam /etc/nginx/dhparams.pem;
        ssl_session_timeout 1d;
        ssl_session_cache shared:MozSSL:10m;
        ssl_session_tickets off;
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
        ssl_prefer_server_ciphers off;
        # 开启 OCSP stapling
        ssl_stapling on;
        ssl_stapling_verify on;
        server_name api.bestfreemall.com;
        location / {
                # Forward incoming requests to local tusd instance
                proxy_pass http://localhost:8080;
                # Disable request and response buffering
                proxy_request_buffering  off;
                proxy_buffering          off;
                proxy_http_version       1.1;
                # Add X-Forwarded-* headers
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header         Upgrade $http_upgrade;
                proxy_set_header         Connection "upgrade";
                client_max_body_size     0;
        }
更新于 阅读次数