如何使用 Node.js 中的 gs:// URI 从 Google Cloud Storage 下载对象?

How do you download an object from Google Cloud Storage with a gs:// URI in Node.js?

我有 gs:// 到 Google 云存储中对象的字符串 URI(参见 for an explanation of what gs:// URIs mean). How do I download these objects using Node.js? The docs 仅包含存储桶名称和文件路径的示例:

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

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

我可以直接从 gs:// URI(作为字符串传递)生成 file,还是需要手动将 URI 解析为存储桶名称和文件路径?

您正在寻找的是使用对象 URI 从云存储获取文件,即 gs://bucket_name/file_name。答案是不可能完成您正在寻找的任务。此外,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 回购。