upload-r2
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUpload R2 Asset
上传 R2 资源
Use this for large media assets that should be hosted on instead of committed to Git.
https://remotion.media/用于应托管在 而不是提交到 Git 的大型媒体资源。
https://remotion.media/Workflow
工作流
-
Find the main worktree:bash
git worktree list --porcelainPrefer the worktree on, usuallyrefs/heads/main./Users/jonathanburger/remotion -
Load R2 credentials from the main worktree:bash
--env-file=/Users/jonathanburger/remotion/packages/remotion-media/.envDo not print secret values. The required variables areandAWS_ACCESS_KEY_ID.AWS_SECRET_ACCESS_KEY -
Upload the file to thebucket using Bun's S3-compatible client:
parser-mediabashbun --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);" -
Verify the public URL:bash
curl -I --fail https://remotion.media/<remote-file-name> -
Replace local asset usage with the hosted URL and delete the local binary.Do not wrap remote URLs in:
staticFile()rejectsstaticFile()andhttp://URLs. Use the URL string directly, for example:https://tsx<Video src="https://remotion.media/example.mp4" /> -
Run the focused lint or stylecheck for touched packages, then commit and push.
-
查找主 worktree:bash
git worktree list --porcelain优先使用位于上的 worktree,通常为refs/heads/main。/Users/jonathanburger/remotion -
从主 worktree 加载 R2 凭证:bash
--env-file=/Users/jonathanburger/remotion/packages/remotion-media/.env不要打印密钥值。所需变量为和AWS_ACCESS_KEY_ID。AWS_SECRET_ACCESS_KEY -
使用 Bun 的 S3 兼容客户端将文件上传到存储桶:
parser-mediabashbun --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);" -
验证公共 URL:bash
curl -I --fail https://remotion.media/<remote-file-name> -
将本地资源的使用方式替换为托管 URL,并删除本地二进制文件。不要使用包装远程 URL:
staticFile()会拒绝staticFile()和http://URL。请直接使用 URL 字符串,例如:https://tsx<Video src="https://remotion.media/example.mp4" /> -
对受影响的包运行针对性的 lint 或 stylecheck,然后提交并推送。