简体   繁体   English

Google Cloud 存储不是一项功能

[英]Google Cloud storage is not a function

I am trying to connect to the Google Cloud Bucket through我正在尝试通过以下方式连接到 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>)

but I am getting an error that storage is not a function.但我收到一个错误,即存储不是一个功能。 Is there some issue that i am missing?有什么我遗漏的问题吗?

By using the Node.js Cloud Storage client libraries version 2.3.4 I was able to connect to a bucket with this code: 通过使用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')

This was based on the Quickstart documentation and the constructor options 这基于Quickstart文档构造函数选项

Hope it helps. 希望能帮助到你。

The recommended methods didn't work for me, while updating GCS from 1.x to 5.x on an older project.在旧项目上将 GCS 从 1.x 更新到 5.x 时,推荐的方法对我不起作用。 Node 14, CommonJs (not modules). Node 14,CommonJs(不是模块)。

But this finally worked:但这终于奏效了:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 谷歌云存储的 firebase 云函数 API 错误 - firebase cloud function API Error with Google Cloud Storage 将图像从Google Cloud功能上传到云端存储 - Upload Image from Google Cloud Function to Cloud Storage 谷歌云存储的修订 - Revisions in google cloud storage Google云功能-存储-删除图像-“ ApiError:请求期间出错” - Google Cloud Function - Storage - Delete Image - “ApiError: Error during request” 谷歌云函数下载文件并重定向到bucket存储 - Google cloud function download file and redirect to bucket storage Express + Multer + Google Cloud Storage 错误:“需要回调函数” - Express + Multer + Google Cloud Storage Error: “Requires a callback function” 在由存储触发的 Google Cloud 函数中提供上下文 - Make context available in Google Cloud function triggered by Storage 将原始数据上传到 Google Cloud 函数中的 Firebase 存储桶? - uploading raw data to a firebase storage bucket in a Google Cloud function? 如何在 Google Cloud Function 的 /tmp 文件夹中下载文件,然后将其上传到 Google Cloud Storage - How to download files in /tmp folder of Google Cloud Function and then upload it in Google Cloud Storage 从 Google Cloud Function 将大文件上传到 Google Cloud Storage 失败 - Failed large file upload to Google Cloud Storage from Google Cloud Function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM