我尝试使用下面的代码应用于firebase 9的照片上传:
const uploadTask = storage.ref(`images/${image.name}`).put(image);以及:
storage
.ref("images")
.child(image.name)
.getDownloadUrl()
.then(url => {
// post image inside the database
db.collection("posts").add({
timestamp: Firebase.ServerValue.TIMESTAMP,
caption: caption,
imageUrl: url,
username: username
});
// set progress back to 0 once it's done! and reset everything else
setProgress(0);
setCaption("");
setImage(null);
})但是,在运行我的代码时,一个错误: TypeError: TypeError不是一个函数
我该怎么解决这个问题?
发布于 2021-10-14 03:12:11
您所显示的代码对于firebase 8看起来是正确的,但是您说您使用的是版本9。版本9有一些重要的更改。因此,您需要回滚到版本8,或者更新代码以使用新的模式。例如,您的第一个代码片段现在如下所示:
import { getStorage, ref, uploadBytes } from "firebase/storage"
const storage = getStorage();
const storageRef = ref(storage, `images/${image.name}`);
const uploadTask = uploadBytes(storageRef);您可以在这里看到更多的信息和示例:https://firebase.google.com/docs/storage/web/upload-files
关于如何升级的说明可以在这里找到:https://firebase.google.com/docs/web/modular-upgrade
https://stackoverflow.com/questions/69564587
复制相似问题