我正在构建一个应用程序,我的目标是每次有人将图像上传到 firebase 存储时,云函数都会调整该图像的大小。
...
import * as Storage from '@google-cloud/storage'
const gcs = new Storage()
...
exports.resizeImage = functions.storage.object().onFinalize( async object => {
const bucket = gcs.bucket(object.bucket);
const filePath = object.name;
const fileName = filePath.split('/').pop();
const bucketDir = dirname(filePath);
....
当我尝试部署此功能时,出现此错误:
Error: Error occurred while parsing your function triggers.
TypeError: Storage is not a constructor
我尝试使用“new Storage()”或只是“Storage”,但没有任何效果。
我是这里的新手,所以如果有什么我忘记让你调试的,请告诉我。
Thanks!
谷歌云/存储:2.0.0
节点js:v8.11.4
The 云存储 API 文档建议您应该使用 require 来加载模块:
const Storage = require('@google-cloud/storage');
这适用于 2.x 版之前的 Cloud Storage 版本。
在 2.x 中,API 发生了重大变化。你现在需要这样做:
const { Storage } = require('@google-cloud/storage');
如果您需要 TypeScript 绑定,请考虑通过 Firebase Admin SDK 使用 Cloud Storage。Admin SDK 只是封装了 Cloud Storage 模块,并且还导出类型绑定以与其一起使用。它很容易使用:
import * as admin from 'firebase-admin'
admin.initializeApp()
admin.storage().bucket(...)
admin.storage()
为您提供对您尝试使用的存储对象的引用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)