【发布时间】:2023-03-13 06:30:01
【问题描述】:
使用 Firebase 存储存储图像时,图像的 URL 如下所示: https://firebasestorage.googleapis.com/v0/b/[MY-APP].appspot.com/o/[FILE-NAME]?alt=media&token=[TOKEN]
我想获取这个网址。
根据this、this、this 和this,我需要使用“存储引用”上的.getDownloadURL() 方法.. 但是可用对象的文档确实与实物不符。
当我尝试访问下面代码中文档建议的对象上的 .getDownloadURL() 方法时,我收到各种未找到属性的错误。
const admin = require('firebase-admin');
admin.initializeApp();
admin
.storage()
.bucket()
.upload(imageToBeUploaded.filepath, {
destination: storageFolder,
resumable: false,
metadata: {
metadata: {
contentType: imageToBeUploaded.mimetype
}
}
})
.then((taskSnapshot) => {
// HOW DO I GET THE DOWNLOADABLE URL
})
我尝试了以下方法:
taskSnapshot[1].getDownloadURL(),
admin.storage().ref(storageFolder+'/'+imageFileName).getDownloadURL(),
admin.storageRef(storageFolder+'/'+imageFileName).getDownloadURL(),
admin.storage().ref().child(storageFolder+'/'+imageFileName).getDownloadURL(),
.. 和一堆其他人。
反复试验是找不到具有该方法的“storageRef”,
如何获取图片的可下载网址?
【问题讨论】:
标签: firebase google-cloud-functions firebase-storage firebase-admin