【发布时间】:2019-01-20 17:13:17
【问题描述】:
尝试使用 RxFire 在 Google Cloud Storage 中上传大图像文件时出现错误:storage/object-not-found。
他们说图片在存储桶中找不到,但当我检查时,我看到了!
我用小图像(可能是 100kb...)进行了测试,效果很好。
但尝试使用 > 500kb 的图像,不起作用...
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"}
【问题讨论】:
-
我猜 getDownloadURL 在上传完全完成之前就被调用了。
-
嘿,是的,这很奇怪.. 使用 8kb 文件,它可以工作,但是当我达到 300kb 左右时,就会出现此错误。我正在等待传输的字节数 === 总字节数.. 但也许这还不够?
-
使用常规 javascript APIS,您等待 UploadTask 承诺解决,或者等待 UploadTaskSnapshot 状态为“SUCCESS”。
-
好吧,我现在使用常规的 .put() 方法使用 Promise,它工作正常......谢谢。但是如果有人对 RxJs 有同样的问题,请随时分享:D
-
当
AngularFireStorageReference和AngularFireUploadTask提到不同的文件名时,我遇到了这个问题,因为我的错误包括其中一个时间戳,而另一个没有。最后,const fileName = file.name + '_' + Date.now();等变量声明和AngularFireStorageReference和AngularFireUploadTask创建的这两个对象中的引用起到了作用。
标签: firebase google-cloud-storage firebase-storage rxfire