微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

上传文件到谷歌云存储使用链接

如何解决上传文件到谷歌云存储使用链接

我尝试从链接上传文件到 GCS,但我不知道该怎么做,

这是我的代码

app.post("/uploads",upload.any("tmparr"),async (req,res) => {
  await storage
    .bucket(bucketName)
    .upload(
      "https://lalalai.s3-us-west-2.amazonaws.com/media/split/9f6f7cb6-43b2-45ee-bec7-16ae2f7214b5/vocals",{
        gzip: true,Metadata: {
          cacheControl: "public,max-age=31536000",},}
    );
  console.log("done");
}); 

我遇到了这样的错误

(node:56016) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory,stat 'D:\reactjs\crud-mern\server\https:\lalalai.s3-us-west-2.amazonaws.com\media\split\9f6f7cb6-43b2-45ee-bec7-16ae2f7214b5\vocals'
(Use `node --trace-warnings ...` to show where the warning was created)
(node:56016) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This 
error originated either by throwing inside of an async function without a catch block,or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:56016) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the 
Node.js process with a non-zero exit code.

有人可以帮我解决吗?谢谢

解决方法

Cloud Storage 不接受文件的 url 链接作为上传参数,正如您在 bucket.upload()documentation 中看到的那样:

要上传到存储桶的文件的完全限定路径。

您收到的错误消息证明了这一点,因为它试图将 URL 解释为本地系统上的路径。

因此,为了完成这项工作,您必须首先从链接下载所述文件,然后才调用 GCS SDK 并上传。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。