代码非常简单
const sharp = require('sharp');
const admin = require('firebase-admin');
const fecha = require('fecha');
admin.initializeApp({
serviceAccountId: '<service-account>.iam.gserviceaccount.com',
databaseURL: "<database-url>",
storageBucket: "<storage-bucket>",
projectId: "<project-id>"
});
const storage = admin.storage();
// console.log(storage.bucket().ref('/general/reviews/1/test.jpg'));
console.log(storage.ref('/general/reviews/1/file.txt').putString('casacasacasa'));我将此代码放入一个云函数中,但它崩溃了
storage.bucket(...).ref is not a function at exports.madrid (/workspace/index.js:666:30) at process.nextTick (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:100:17) at process._tickCallback (internal/process/next_tick.js:61:11)如果我取消第一行的注释,它就会
TypeError: storage.ref is not a function at exports.madrid (/workspace/index.js:666:21) at process.nextTick (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:100:17) at process._tickCallback (internal/process/next_tick.js:61:11)我是100%的桶存在,这是非常相同的代码在android sdk上运行良好…我做错了什么?
发布于 2021-04-20 18:29:14
如果您使用storage的firebase-admin,请注意,您必须遵循以下文档:https://googleapis.dev/nodejs/storage/latest/
使用firebase-admin时,ref函数将被file替换,如下所示:
admin.storage().bucket().file(remotePath).save(buffer)
https://stackoverflow.com/questions/67163250
复制相似问题