如何使用firebase存储桶节点sdk



代码是超简单的

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上运行得很好。。。我做错了什么?

如果将firebase-admin用于storage,请务必遵守文档:https://googleapis.dev/nodejs/storage/latest/

使用firebase-adminref功能被file取代,如下所示:

admin.storage().bucket().file(remotePath).save(buffer)

最新更新