簡體   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?

我有gs://字符串 URI 指向 Google Cloud Storage 中的對象(有關gs:// URI 含義的解釋,請參閱此問題)。 如何使用 Node.js 下載這些對象? 文檔僅包含具有存儲桶名稱和文件路徑的示例:

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 答案是不可能完成您正在尋找的任務。 此外, NodeJSCloud Storage官方客戶端庫沒有提供任何此類方法。 因此,您必須解析對象 URI 並首先使用 Storage 客戶端獲取存儲桶,然后使用存儲桶獲取此處或此github 存儲庫中提到的對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM