uploadToVercelBlob()v4.0.426
实验性包:我们保留在本通知取消之前,为了纠正糟糕的设计决策而进行重大更改的权利。
将文件从沙箱上传到 Vercel Blob 存储。通常在 renderMediaOnVercel() 或 renderStillOnVercel() 之后使用,以使输出可公开访问。
🌐 Uploads a file from the sandbox to Vercel Blob storage. Typically used after renderMediaOnVercel() or renderStillOnVercel() to make the output publicly accessible.
示例
🌐 Example
route.tsconst {url ,size } = awaituploadToVercelBlob ({sandbox ,sandboxFilePath : '/tmp/video.mp4',contentType : 'video/mp4',blobToken :process .env .BLOB_READ_WRITE_TOKEN !,access : 'public', });console .log (`Uploaded ${size } bytes to ${url }`);
参数
🌐 Arguments
一个具有以下属性的对象:
🌐 An object with the following properties:
sandbox
一个 Sandbox 实例。
🌐 A Sandbox instance.
sandboxFilePath
要上传的沙箱内文件的路径,例如 "/tmp/video.mp4"。
🌐 The path to the file inside the sandbox to upload, e.g. "/tmp/video.mp4".
blobPath?
Vercel Blob 中的目标路径,例如 "renders/abc.mp4"。如果省略,将生成一个随机路径。
🌐 The destination path in Vercel Blob, e.g. "renders/abc.mp4". If omitted, a random path is generated.
contentType
文件的 MIME 类型,例如 "video/mp4" 或 "image/png"。
🌐 The MIME type of the file, e.g. "video/mp4" or "image/png".
blobToken
你的 Vercel Blob 读/写令牌。通常为 process.env.BLOB_READ_WRITE_TOKEN。
🌐 Your Vercel Blob read/write token. Typically process.env.BLOB_READ_WRITE_TOKEN.
access
VercelBlobAccess
上传的 blob 的访问级别。可以是 "public" 或 "private"。默认值:"private"。
🌐 The access level of the uploaded blob. Either "public" or "private". Default: "private".
返回值
🌐 Return value
包含以下内容的对象:
🌐 An object containing:
url
已上传文件的公共下载链接。
🌐 The public download URL of the uploaded file.
size
上传文件的字节大小。
🌐 The size of the uploaded file in bytes.
另请参阅
🌐 See also