1

I try to upload a file from the link to GCS but I don't know how to do it,

This is my code

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");
}); 

I got an error like this

(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.

Can someone help me to fix it? thank you

Ralemos
  • 5,571
  • 2
  • 9
  • 18
ubi goreng
  • 53
  • 7

1 Answers1

0

Cloud Storage does not accepts a url link to a file as a parameter for upload, as you can see in the documentation for bucket.upload() it requires:

The fully qualified path to the file you wish to upload to your bucket.

And the error message you get is proof of this, since it tries to interpret the URL as a path on your local system.

So in order to make this work you have to first download said file from the link and only then call for the GCS SDK and upload it.

Ralemos
  • 5,571
  • 2
  • 9
  • 18