繁体   English   中英

如何在angular中使用谷歌云存储的签名URL下载文件

[英]How to download a file using the signed URL of google cloud storage in angular

我已经在 GCP 中为一个文件返回了签名的 url 作为响应,现在我想用它通过我的 angular 前端下载这个文件。 我试过动态附加锚标记,但不是下载它,而是只显示文件。 有人知道这个的解决方案吗? 这就是它目前的样子。 提前致谢 ! 在此处输入图像描述

您可以将GetSignedUrlConfig中的responseDisposition属性设置为attachment ,如下所示:

const [url] = await storage
  .bucket("[bucket]")
  .file("[path]")
  .getSignedUrl({
    version: "v4",
    action: "read",
    responseDisposition: "attachment", 
    // optionally specify file name
    // responseDisposition: "attachment; filename=name.ext",
    expires: Date.now() + 15 * 60 * 1000,
  });

return url;

然后在获得签名的 URL 后重定向到 URL,如下所示:

window.open(this.downloadUrl, '_blank').focus();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM