我得到:
可能的未处理Promise拒绝(id:0):TypeError:undefined不是对象(正在计算“ref._location')`
我甚至把裁判改成
import { ref as refstore, uploadBytesResumable, getDownloadURL } from "firebase/storage";
这样就不会互相碰撞。并改变图像斑点。我被困在这里不知道下一步该做什么。
const uploadImage = async () => {
const blobimage = await new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.onload = function () {
resolve(xhr.response);
};
xhr.onerror = function () {
reject(new TypeError("Network request failed"));
};
xhr.responseType = "blob";
xhr.open("GET", imageUri, true);
xhr.send(null);
})
const metadata = {
contentType: 'image/jpeg'
};
// I think something is wrong in the below line **storageRef** <------------
const storageRef = refstore(storage,`images/${Date.now()}`);
const uploadTask = uploadBytesResumable(storageRef, blobimage, metadata);
uploadTask.on('state_changed',
(snapshot) => {
const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log('Upload is ' + progress + '% done');
switch (snapshot.state) {
case 'paused':
console.log('Upload is paused');
break;
case 'running':
console.log('Upload is running');
break;
}
},
);
};
2条答案
按热度按时间irlmq6kh1#
需要通过getStorage预建函数定义storage变量。
就像这样:
初始化Firebase存储后,您可以将存储对象传递给refstore:
vkc1a9a22#
从配置文件导入时,不要忘记在导入时使用{}。