[英]How do you download an object from Google Cloud Storage with a gs:// URI in Node.js?
I have gs://
string URIs to objects in Google Cloud Storage (see this question for an explanation of what gs://
URIs mean).我有gs://
字符串 URI 指向 Google Cloud Storage 中的对象(有关gs://
URI 含义的解释,请参阅此问题)。 How do I download these objects using Node.js?如何使用 Node.js 下载这些对象? Thedocs 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?我可以直接从gs://
URI 创建file
(作为字符串传递),还是需要手动将 URI 解析为存储桶名称和文件路径?
What you are looking for is getting a file from the Cloud Storage using the object URI ie gs://bucket_name/file_name
.您正在寻找的是使用对象 URI 从云存储获取文件,即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.此外, NodeJS中Cloud Storage的官方客户端库没有提供任何此类方法。 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 mentionedhere or in this github repo.因此,您必须解析对象 URI 并首先使用 Storage 客户端获取存储桶,然后使用存储桶获取此处或此github 存储库中提到的对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.