S3 上传
Learn how to upload files to Supabase Storage using S3.
你可以使用 S3 协议将文件上传到 Supabase Storage。要开始使用 S3,请参阅 S3 设置指南。
🌐 You can use the S3 protocol to upload files to Supabase Storage. To get started with S3, see the S3 setup guide.
S3 协议支持使用以下方式上传文件:
🌐 The S3 protocol supports file upload using:
- 一个请求
- 通过多部分上传的多个请求
单次请求上传 #
🌐 Single request uploads
PutObject 操作通过一次请求上传文件。这与 Supabase SDK 的 标准上传 行为相同。
🌐 The PutObject action uploads the file in a single request. This matches the behavior of the Supabase SDK Standard Upload.
使用 PutObject 上传较小的文件,这样即使需要重试整个上传也不会有问题。付费计划的最大文件大小是 500 GB。
🌐 Use PutObject to upload smaller files, where retrying the entire upload won't be an issue. The maximum file size on paid plans is 500 GB.
例如,使用 JavaScript 和 aws-sdk 客户端:
🌐 For example, using JavaScript and the aws-sdk client:
1import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'23const s3Client = new S3Client({...})45const file = fs.createReadStream('path/to/file')67const uploadCommand = new PutObjectCommand({8 Bucket: 'bucket-name',9 Key: 'path/to/file',10 Body: file,11 ContentType: 'image/jpeg',12})1314await s3Client.send(uploadCommand)分段上传 #
🌐 Multipart uploads
分块上传会把文件拆成更小的部分并行上传,在高速网络下可以最大化上传速度。在上传大文件时,如果遇到网络问题,你可以单独重试某些部分的上传。
🌐 Multipart Uploads split the file into smaller parts and upload them in parallel, maximizing the upload speed on a fast network. When uploading large files, this allows you to retry the upload of individual parts in case of network issues.
当你希望以牺牲可续传性为代价最大化上传速度时,这种方法比可续传上传更适合用于服务器端上传。付费计划的最大文件大小为500 GB。
🌐 This method is preferable over Resumable Upload for server-side uploads, when you want to maximize upload speed at the cost of resumability. The maximum file size on paid plans is 500 GB.
分部分上传文件 #
🌐 Upload a file in parts
使用 S3 客户端的 Upload 类将文件分部分上传。例如,使用 JavaScript :
🌐 Use the Upload class from an S3 client to upload a file in parts. For example, using JavaScript:
1import { S3Client } from '@aws-sdk/client-s3'2import { Upload } from '@aws-sdk/lib-storage'34const s3Client = new S3Client({...})56const file = fs.createReadStream('path/to/very-large-file')78const upload = new Upload(s3Client, {9 Bucket: 'bucket-name',10 Key: 'path/to/file',11 ContentType: 'image/jpeg',12 Body: file,13})1415await uploader.done()中止多部分上传 #
🌐 Aborting multipart uploads
所有分段上传会在 24 小时后自动中止。如果你想在那之前中止分段上传,可以使用 AbortMultipartUpload 操作。
🌐 All multipart uploads are automatically aborted after 24 hours. To abort a multipart upload before that, you can use the AbortMultipartUpload action.