Google 云存储:下载文件名包含存储桶中的路径
Google Cloud Storage: Download filename contains path in bucket
我正在将带有 firebase 存储的文件上传到 some/path/file.txt
后来我得到一个下载 url 并在浏览器中通过 link 提供下载。当用户下载该文件时,它被命名为 file.txt
现在我通过gcloud存储用云函数修改这个文件。我重新上传它:
bucket.upload(localfile, {destination: 'some/path/file.txt'});
现在用户下载文件时,浏览器中建议的文件名是:some%2path%2file.txt
有没有办法避免这种情况?
是的,将文件的 Content-Disposition
header 设置为仅包含 file.txt
。类似于:
bucket.upload(localFile, {
destination: 'some/path/file.txt'
metadata: {
contentDisposition: 'attachment; filename="file.txt"'
}
});
我正在将带有 firebase 存储的文件上传到 some/path/file.txt 后来我得到一个下载 url 并在浏览器中通过 link 提供下载。当用户下载该文件时,它被命名为 file.txt
现在我通过gcloud存储用云函数修改这个文件。我重新上传它:
bucket.upload(localfile, {destination: 'some/path/file.txt'});
现在用户下载文件时,浏览器中建议的文件名是:some%2path%2file.txt
有没有办法避免这种情况?
是的,将文件的 Content-Disposition
header 设置为仅包含 file.txt
。类似于:
bucket.upload(localFile, {
destination: 'some/path/file.txt'
metadata: {
contentDisposition: 'attachment; filename="file.txt"'
}
});