【发布时间】:2018-04-14 20:01:51
【问题描述】:
我使用 firebase-admin 和 firebase-functions 在 Firebase Storage 中上传文件。
我在存储中有这个规则:
service firebase.storage {
match /b/{bucket}/o {
match /images {
allow read;
allow write: if false;
}
}
}
我想用这个代码获得一个公共 URL:
const config = functions.config().firebase;
const firebase = admin.initializeApp(config);
const bucketRef = firebase.storage();
server.post('/upload', async (req, res) => {
// UPLOAD FILE
await stream.on('finish', async () => {
const fileUrl = bucketRef
.child(`images/${fileName}`)
.getDownloadUrl()
.getResult();
return res.status(200).send(fileUrl);
});
});
但是我有这个错误.child is not a function。
如何使用 firebase-admin 获取文件的公共 url?
【问题讨论】:
标签: firebase google-cloud-storage firebase-storage firebase-admin