Google Cloud 存储不是一项功能

anu*_*ysh 6 node.js google-cloud-storage google-cloud-platform

我正在尝试通过以下方式连接到 Google Cloud Bucket

 const storage = require('@google-cloud/storage');
 const gcs = storage({    //TypeError: storage is not a function
  "keyFileName": 'path-to-keyfile.json',
  "type": "service_account",
  "project_id": <PROJECT_NAME>,

 //SOME CREDENTIALS
});

const bucket = gcs.bucket(<BUCKET_NAME>)
Run Code Online (Sandbox Code Playgroud)

但我收到一个错误,即存储不是一个功能。有什么我遗漏的问题吗?

F10*_*F10 8

通过使用 Node.js Cloud Storage 客户端库版本 2.3.4,我能够使用以下代码连接到存储桶:

'use strict';

async function quickstart(
  projectId = 'PROJECT_ID', // Your Google Cloud Platform project ID
  keyFilename = '/home/folder/key.json' //Full path of the JSON file
) {
  // Imports the Google Cloud client library
  const {Storage} = require('@google-cloud/storage');

  // Creates a client
  const storage = new Storage({keyFilename,projectId});
  const bucket = storage.bucket('BUCKET_NAME')
Run Code Online (Sandbox Code Playgroud)

这是基于快速入门文档构造函数选项

希望能帮助到你。