0

I have gs:// string URIs to objects in Google Cloud Storage (see this question for an explanation of what gs:// URIs mean). How do I download these objects using Node.js? The docs only contain examples with the bucket name and file path:

const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const myBucket = storage.bucket('my-bucket');

const file = myBucket.file('my-file');

Can I make a file directly from a gs:// URI (passed as a string), or do I need to manually parse the URI into a bucket name and file path?

sffc
  • 6,186
  • 3
  • 44
  • 68
  • Does this answer your question? [What does gs protocol mean?](https://stackoverflow.com/questions/38806490/what-does-gs-protocol-mean) – Ouroborus Nov 15 '21 at 01:59
  • No, I'm aware of what the gs protocol means, and I want to use it in Node.js to download files from the Google Cloud Storage SDK. – sffc Nov 15 '21 at 03:27
  • Then you should know that the `gs:` protocol is only for use with `gsutil`. `gs:` is basically shorthand rather than a proper protocol. If you want to access those resources via a client API, don't use `gs:`, just as the documentation dictates. – Ouroborus Nov 15 '21 at 03:38
  • The `gs://` protocol is a useful interchange format for stable addresses of Google Cloud Storage objects. It is used widely in Google Cloud Platform user interfaces as well as the `gsutil` command-line tool. – sffc Nov 23 '21 at 07:16
  • `gs://` is just shorthand for `https://storage.googleapis.com/`. There's no difference between the two. – Ouroborus Nov 23 '21 at 08:18

1 Answers1

0

What you are looking for is getting a file from the Cloud Storage using the object URI i.e. gs://bucket_name/file_name. The answer to this is it is not possible to do the task you are looking for. Also, the official client library for Cloud Storage in NodeJS does not provide any such method to do it. So you have to parse the object URI and first get the bucket using the Storage client, then use the bucket to get the object as mentioned here or in this github repo.

Prabir
  • 1,415
  • 4
  • 10