Google云存储不起作用

时间:2019-01-02 12:20:40

标签: node.js google-cloud-platform google-cloud-storage

我正在尝试通过

连接到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>)

但是我收到一个错误,指出存储不是功能。我缺少一些问题吗?

1 个答案:

答案 0 :(得分:2)

使用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')

这是基于Quickstart documentationconstructor options

希望有帮助。