Firebase 错误:尝试上载大型图像文件时未找到存储/对象
我遇到了一个错误:当尝试使用RxFire在Google云存储中上载大型图像文件时,找不到存储/对象 他们说在水桶里找不到图像,但当我检查时,我看到了它们 我用小图像(可能是100kb…)进行了测试,效果很好 但是尝试使用>500kb的图像,不起作用Firebase 错误:尝试上载大型图像文件时未找到存储/对象,firebase,google-cloud-storage,firebase-storage,rxfire,Firebase,Google Cloud Storage,Firebase Storage,Rxfire,我遇到了一个错误:当尝试使用RxFire在Google云存储中上载大型图像文件时,找不到存储/对象 他们说在水桶里找不到图像,但当我检查时,我看到了它们 我用小图像(可能是100kb…)进行了测试,效果很好 但是尝试使用>500kb的图像,不起作用 upload$ .pipe( switchMap((event: any) => { const name = Math.random().toString(36).substring(5); const b
upload$
.pipe(
switchMap((event: any) => {
const name = Math.random().toString(36).substring(5);
const blob = event.target.files[0];
const type = blob.type.replace('image/', '');
const ref = storage.ref(`uploads/test/${name}.${type}`);
return put(ref, blob);
}),
map(snapshot => snapshot),
filter(snapshot => snapshot.totalBytes === snapshot.bytesTransferred),
mergeMap(snapshot => getDownloadURL(snapshot.ref))
)
.subscribe(url => {
console.log('Results', url)
}, (error) => {
// ERROR HERE
console.log('error', error)
})
预期结果:上传大图像
实际结果:错误
Uncaught t {code_: "storage/object-not-found", message_: "Firebase .
Storage: Object 'uploads/test/7xpbilmb.jpeg' does not exist.",
serverResponse_: "{↵ "error": {↵ "code": 404,↵ "message":
"Not Found. Could not get object"↵ }↵}", name_: "FirebaseError"}
两种方法都可以
storageRef.put(blob, {customMetadata}).then(data => {
data.ref.getDownloadURL().then(url => {
// do whatever you want with url
});
});
downloadURL = new Subject();
this.downloadURL.pipe(
map(obs => obs),
concatAll()
).subscribe(url => {
// do whatever you want with url
});
let task = ref.put(blob, {customMetadata});
task.snapshotChanges().pipe(
finalize(() => this.downloadURL.next(ref.getDownloadURL()))
).subscribe();
task.percentageChanges().subscribe(progress => {
console.log('upload progress: ', progress);
if (res >= 100) {
// HOORAY!
}
});
我猜getDownloadURL在上传完成之前被调用了。嘿,是的,那是wierd。。对于8kb的文件,它可以工作,但是当我达到300kb左右时,就会出现这个错误。我正在等待传输的字节数===总字节数。。但这可能还不够?对于常规的javascript API,您需要等待UploadTask承诺的解决,或者等待UploadTaskSnapshot状态为“成功”。好的,我现在将承诺与常规的.put()方法一起使用,它工作得很好。。。谢谢但是,如果有人对RxJs有同样的问题,请随意分享:当
AngularFireStorageReference
和AngularFireUploadTask
引用了不同的文件名时,我遇到了这个问题,因为我的错误包括其中一个时间戳,而另一个没有。最后,变量声明,如constfilename=file.name+'.'+Date.now()由AngularFireStorageReference
和AngularFireUploadTask
创建的这两个对象中的code>和reference都起到了作用。