简体   繁体   English

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

[英]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.此外, NodeJSCloud 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.

相关问题 如何使用 Node.js 将 Blob base64 字符串上传到谷歌云存储 - How do you upload a blob base64 string to google cloud storage using Node.js 从Google Cloud Storage下载多个文件(使用node.js) - Download multiple files from Google Cloud Storage (using node.js) 如何使用 Node.js 将 base64 编码的图像(字符串)直接上传到 Google Cloud Storage 存储桶? - How do I upload a base64 encoded image (string) directly to a Google Cloud Storage bucket using Node.js? 如何从谷歌驱动器 api 下载带有 Node.js 的文件 - How to download a file with Node.js from google drive api 使用 Node.js 和 Google Cloud Storage 压缩图像 - Compressing Images with Node.js and Google Cloud Storage 使用 Node.js 将 pdf 文件上传到 Google Cloud Storage - Upload a pdf file to Google Cloud Storage with Node.js Google Cloud Storage使用Node.js更改通知 - Google Cloud Storage change notifications with Node.js 获取/设置谷歌云存储中的元数据 - node.js - Getting/Setting metadata in google cloud storage - node.js 使用node.js为Google云端存储创建已签名的网址,以便从浏览器直接上传 - Create signed URLs for Google Cloud Storage with node.js for direct upload from browser 如何从Node.js上的Google地理编码API返回结果 - How do you return the result from the google geocoding API on Node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM