网淘吧来吧,欢迎您!

Send Me My Files - R2 upload with short lived signed urls技能使用说明

2026-03-29 新闻来源:网淘吧 围观:11
电脑广告
手机广告

发送我的文件 - 使用短时签名URL上传至R2

将文件上传至Cloudflare R2或任何S3兼容存储,并生成预签名的下载链接。

功能

  • 上传文件至R2/S3存储桶
  • 生成预签名下载URL(可配置过期时间)
  • 支持任何S3兼容存储(R2、AWS S3、MinIO等)
  • 多存储桶配置
  • 自动检测内容类型

配置

创建~/.r2-upload.yml(或设置R2_UPLOAD_CONFIG环境变量):

Send Me My Files - R2 upload with short lived signed urls

# Default bucket (used when no bucket specified)
default: my-bucket

# Bucket configurations
buckets:
  my-bucket:
    endpoint: https://abc123.r2.cloudflarestorage.com
    access_key_id: your_access_key
    secret_access_key: your_secret_key
    bucket_name: my-bucket
    public_url: https://files.example.com  # Optional: custom domain
    region: auto  # For R2, use "auto"
    
  # Additional buckets
  personal:
    endpoint: https://xyz789.r2.cloudflarestorage.com
    access_key_id: ...
    secret_access_key: ...
    bucket_name: personal-files
    region: auto

Cloudflare R2 设置

  1. 前往Cloudflare仪表盘 → R2
  2. 创建一个存储桶
  3. 前往R2 API令牌页面:https://dash.cloudflare.com/<ACCOUNT_ID>/r2/api-tokens
  4. 创建一个新的API令牌
    • 重要提示:应用到特定存储桶(选择您的存储桶)
    • 权限:对象读写
  5. 复制访问密钥ID和秘密访问密钥
  6. 使用端点格式:https://<account_id>.r2.cloudflarestorage.com
  7. 设置区域:自动

AWS S3 设置

aws-bucket:
  endpoint: https://s3.us-east-1.amazonaws.com
  access_key_id: ...
  secret_access_key: ...
  bucket_name: my-aws-bucket
  region: us-east-1

使用

上传文件

r2-upload /path/to/file.pdf
# Returns: https://files.example.com/abc123/file.pdf?signature=...

使用自定义路径上传

r2-upload /path/to/file.pdf --key uploads/2026/file.pdf

上传到特定存储桶

r2-upload /path/to/file.pdf --bucket personal

自定义过期时间(默认:5分钟)

r2-upload /path/to/file.pdf --expires 24h
r2-upload /path/to/file.pdf --expires 1d
r2-upload /path/to/file.pdf --expires 300  # seconds

公共URL(无需签名)

r2-upload /path/to/file.pdf --public

工具

  • r2_upload- 上传文件并获取预签名URL
  • r2_list- 列出最近的上传
  • r2_delete- 删除文件

环境变量

  • R2_UPLOAD_CONFIG- 配置文件路径(默认:~/.r2-upload.yml
  • R2_DEFAULT_BUCKET- 覆盖默认存储桶
  • R2_DEFAULT_EXPIRES- 默认过期时间(单位:秒,默认值:300 = 5分钟)

注意事项

  • 上传的文件默认使用原始文件名存储,除非指定了 --key 参数系统会自动添加UUID前缀以防止文件名冲突(例如:
  • abc123/file.pdfContent-Type会根据文件扩展名自动检测
  • 预签名URL将在配置的持续时间后过期
  • Presigned URLs expire after the configured duration

免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏
文章底部电脑广告
手机广告位-内容正文底部

相关文章

您是本站第326290名访客 今日有221篇新文章/评论