dab*_*lak 5 google-app-engine google-cloud-storage
我想知道是否可以从谷歌云存储中下载一个文件,其名称不同于存储桶中的文件.
例如,在谷歌云存储中我存储了一个名为123-file.txt但是当我下载它的文件时,我想选择一个不同的名称,让我们说file.txt
我注意到它的下载链接如下:https: //storage.cloud.google.com/bucket_name%2F123-file.txt ?response-content-disposition=attachment; %20filename = 123-file.txt
所以我试图将其更改为:https: //storage.cloud.google.com/bucket_name%2F123-file.txt ?response-content-disposition=attachment; %20filename = file.txt
但它仍然继续下载为123-file.txt而不是file.txt
response-content-disposition参数只能由授权请求使用.匿名链接无法使用它.你有几个选择:
特定对象的内容处置是其元数据的一部分,可以永久设置.如果您始终希望使用特定名称下载特定文件,则可以永久设置该对象的内容处置元数据.
您还可以生成包含response-content-disposition查询参数的签名URL.然后,用户将发出授权请求以下载资源.
带有 javascript 库的示例(第一个选项 Brandon Yarbrough):
const storage = new Storage()
const fileBucket = storage.bucket('myBucket')
const file = fileBucket.file('MyOriginalFile.txt')
const newName = "NewName.txt"
await file.save(content, {
metadata: {
contentDisposition: `inline; filename="${newName}"`
}
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2132 次 |
| 最近记录: |