2014-01-09 68 views
5

我想知道是否可以从Google云端存储中下载文件的名称与存储区中名称不同。Google云端存储:下载不同名称的文件

例如,在谷歌云存储我已经存储了一个名为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的

回答

6

response-content-disposition参数只能由授权的请求使用。匿名链接不起作用。您有几种选择:

  1. 特定对象的内容处置是其元数据的一部分,可以永久设置。如果您始终希望以特定名称下载特定文件,则可以永久设置该对象的内容处置元数据。

  2. 您还可以生成包含response-content-disposition查询参数的签名URL。然后这些用户将做出授权请求来下载资源。

+1

签名的网址为我工作。虽然,我试着用参数response_headers和值response-content-disposition调用generate_url(),但我得到了畸形签名的url。所以我的解决方案是将'&response-content-disposition = attachment%3B%20filename%3D“{}”'。format(file_name)连接到签名的url并且它工作。 – dablak

+0

记录response-content-disposition查询参数在哪里?其他有效的查询参数是什么? –

+0

有效的XML API参数的完整列表位于https://cloud.google.com/storage/docs/reference-headers –

相关问题