【问题标题】:Google Cloud Storage: Download filename contains path in bucketGoogle Cloud Storage:下载文件名包含存储桶中的路径
【发布时间】:2017-05-16 05:42:38
【问题描述】:

我正在将带有 firebase 存储的文件上传到 some/path/file.txt 后来我得到一个下载网址并通过浏览器中的链接提供下载。当用户下载文件时,它被命名为 file.txt

现在我通过 gcloud storage 使用云功能修改此文件。我重新上传它:

bucket.upload(localfile, {destination: 'some/path/file.txt'});

当用户现在下载文件时,浏览器中的建议文件名是:some%2path%2file.txt

有没有办法避免这种情况?

【问题讨论】:

    标签: google-cloud-storage firebase-storage


    【解决方案1】:

    是的,请将文件的 Content-Disposition 标头设置为仅包含 file.txt。类似的东西:

    bucket.upload(localFile, {
      destination: 'some/path/file.txt'
      metadata: {
        contentDisposition: 'attachment; filename="file.txt"'
      }
    });
    

    【讨论】:

    • 嘿迈克,下载文件时有什么办法吗?
    • @Mike, 1. 我设置了 contentDisposition: 'attachment ;文件名 = "file_name.dsv"'。 2. 使用来自 metaData[0].mediaLink 的下载 url。 3. 从第 2 步打开链接时,文件具有完整路径,在第 1 步中未提及 4. 仅供参考:内容配置保存在元数据中。
    猜你喜欢
    • 2020-09-06
    • 1970-01-01
    • 2021-07-17
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 2018-06-18
    • 2017-11-29
    • 1970-01-01
    相关资源
    最近更新 更多