upload-r2

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Upload R2 Asset

上传 R2 资源

Use this for large media assets that should be hosted on
https://remotion.media/
instead of committed to Git.
用于应托管在
https://remotion.media/
而不是提交到 Git 的大型媒体资源。

Workflow

工作流

  1. Find the main worktree:
    bash
    git worktree list --porcelain
    Prefer the worktree on
    refs/heads/main
    , usually
    /Users/jonathanburger/remotion
    .
  2. Load R2 credentials from the main worktree:
    bash
    --env-file=/Users/jonathanburger/remotion/packages/remotion-media/.env
    Do not print secret values. The required variables are
    AWS_ACCESS_KEY_ID
    and
    AWS_SECRET_ACCESS_KEY
    .
  3. Upload the file to the
    parser-media
    bucket using Bun's S3-compatible client:
    bash
    bun --env-file=/Users/jonathanburger/remotion/packages/remotion-media/.env -e "import {S3Client} from 'bun'; const filePath='<local-file>'; const key='<remote-file-name>'; const client=new S3Client({accessKeyId:Bun.env.AWS_ACCESS_KEY_ID, secretAccessKey:Bun.env.AWS_SECRET_ACCESS_KEY, endpoint:'https://2fe488b3b0f4deee223aef7464784c46.r2.cloudflarestorage.com', bucket:'parser-media'}); const file=Bun.file(filePath); if (await client.exists(key)) { const stat=await client.stat(key); if (stat.size===file.size) { console.log('exists-same-size', key, file.size); process.exit(0); } } await client.write(key, file); const stat=await client.stat(key); console.log('uploaded', key, stat.size);"
  4. Verify the public URL:
    bash
    curl -I --fail https://remotion.media/<remote-file-name>
  5. Replace local asset usage with the hosted URL and delete the local binary.
    Do not wrap remote URLs in
    staticFile()
    :
    staticFile()
    rejects
    http://
    and
    https://
    URLs. Use the URL string directly, for example:
    tsx
    <Video src="https://remotion.media/example.mp4" />
  6. Run the focused lint or stylecheck for touched packages, then commit and push.
  1. 查找主 worktree:
    bash
    git worktree list --porcelain
    优先使用位于
    refs/heads/main
    上的 worktree,通常为
    /Users/jonathanburger/remotion
    。
  2. 从主 worktree 加载 R2 凭证:
    bash
    --env-file=/Users/jonathanburger/remotion/packages/remotion-media/.env
    不要打印密钥值。所需变量为
    AWS_ACCESS_KEY_ID
    和
    AWS_SECRET_ACCESS_KEY
    。
  3. 使用 Bun 的 S3 兼容客户端将文件上传到
    parser-media
    存储桶:
    bash
    bun --env-file=/Users/jonathanburger/remotion/packages/remotion-media/.env -e "import {S3Client} from 'bun'; const filePath='<local-file>'; const key='<remote-file-name>'; const client=new S3Client({accessKeyId:Bun.env.AWS_ACCESS_KEY_ID, secretAccessKey:Bun.env.AWS_SECRET_ACCESS_KEY, endpoint:'https://2fe488b3b0f4deee223aef7464784c46.r2.cloudflarestorage.com', bucket:'parser-media'}); const file=Bun.file(filePath); if (await client.exists(key)) { const stat=await client.stat(key); if (stat.size===file.size) { console.log('exists-same-size', key, file.size); process.exit(0); } } await client.write(key, file); const stat=await client.stat(key); console.log('uploaded', key, stat.size);"
  4. 验证公共 URL:
    bash
    curl -I --fail https://remotion.media/<remote-file-name>
  5. 将本地资源的使用方式替换为托管 URL,并删除本地二进制文件。
    不要使用
    staticFile()
    包装远程 URL:
    staticFile()
    会拒绝
    http://
    和
    https://
    URL。请直接使用 URL 字符串,例如:
    tsx
    <Video src="https://remotion.media/example.mp4" />
  6. 对受影响的包运行针对性的 lint 或 stylecheck,然后提交并推送。