【问题标题】:Google Cloud storage is not a function谷歌云存储不是一项功能
【发布时间】:2019-05-29 02:21:47
【问题描述】:

我正在尝试通过

连接到 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 google-cloud-platform google-cloud-storage


【解决方案1】:

使用 Node.js 云存储客户端库 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

希望对你有帮助。

【讨论】:

    【解决方案2】:

    推荐的方法对我不起作用,同时在旧项目上将 GCS 从 1.x 更新到 5.x。节点 14,CommonJs(不是模块)。

    但这终于奏效了:

    const Storage = require('@google-cloud/storage');
    const gcs = new Storage({gcsProjectId});
    

    【讨论】:

      猜你喜欢
      • 2021-08-20
      • 2017-08-20
      • 2022-12-17
      • 2021-08-21
      • 2017-11-14
      • 2023-02-13
      • 2020-09-10
      • 2018-02-21
      • 2016-10-12
      相关资源
      最近更新 更多