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?
As of @google-cloud/storage
v7.10.0 (2024-04-15) it is now possible to create a file object from an URL.
Example:
import { Storage, File } from '@google-cloud/storage';
const storage = new Storage();
const uri = 'gs://example-bucket/example-file';
const file = File.from(uri, storage).download();