node.js - 谷歌云存储不是一个功能

标签 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>)

但是我得到一个错误,存储不是一个函数。有没有我遗漏的问题?

最佳答案

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

希望对您有所帮助。

关于node.js - 谷歌云存储不是一个功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54006294/

相关文章:

node.js - 我可以更改 winston 中日志数据的颜色吗?

javascript - Node.js 中如何处理 Session?

javascript - 如何将这种类型的数组转换为json对象呢?

javascript - 如何在 couchdb 中获取表的数据

machine-learning - 导入错误: cannot import name JSONClient

java - 如何在访问 Google Drive API 时隐藏/绕过授权弹出窗口

python - 来自 google-cloud-sdk 的 Pylance 问题

kubernetes - 如何在 GCE 上将 NodePort 暴露给互联网

python-3.x - 从 Google Cloud Storage 中的 csv 读取 n 行以与 Python csv 模块一起使用

hadoop - 从 Hadoop 访问只读的 Google Storage 存储桶