javascript – Firebase存储随机返回存储/取消
作者:互联网
我收到一条错误,指出用户取消了上传,我从控制台中的单个上传中收到了三个错误(上传文件时来自firebase存储的错误相同.我无法在代码中看到如何正在取消(假设由于它声明其被用户取消,因此它在代码内).
startUpload(event: FileList, item:string) {
// The File object
const file = event.item(0);
console.log(item);
// Client-side validation example
if (file.type.split('/')[0] !== 'image') {
console.error('unsupported file type')
return;
}
// The storage path
const path = `test/${new Date().getTime()}_${file.name}`;
// Totally optional metadata
const customMetadata = { user: item };
// The main task
this.uploadStatus = 'inprogress';
this.task = this.storage.upload(path, file, { customMetadata })
const fileRef = this.storage.ref(path);
// Progress monitoring
this.percentage = this.task.percentageChanges();
this.snapshot = this.task.snapshotChanges().pipe(
tap(snap => {
if (snap.bytesTransferred === snap.totalBytes) {
// Update firestore on completion
this.db.collection('photos').add( { path, size: snap.totalBytes });
this.uploadStatus = "finished";
}
}),
finalize(()=>{
this.downloadURL = fileRef.getDownloadURL();
console.log("Final");
})
);
}
chrome控制台的完整错误:
“存储/取消”
码_
:
“存储/取消”
信息
:
“Firebase存储:用户取消了上传/下载.”
信息_
:
“Firebase存储:用户取消了上传/下载.”
名称
:
(……)
名称_
:
“FirebaseError”
serverResponse
:
空值
serverResponse_
:
空值
解决方法:
我自己也遇到了这个错误:
FirebaseStorageError {code_: "storage/canceled", message_: "Firebase Storage: User canceled the upload/download.", serverResponse_: null, name_: "FirebaseError"}
我原来的看法
<mat-progress-bar mode="determinate" *ngIf="(uploadPercent | async) == 0" [value]="uploadPercent | async"></mat-progress-bar>
| async
是取消可观察性的罪魁祸首.
解:
<ng-container *ngIf="(uploadPercent$| async); let uploadPercent">
<mat-progress-bar mode="determinate" *ngIf="uploadPercent !== 100" [value]="uploadPercent"></mat-progress-bar>
</ng-container>
标签:javascript,firebase,firebase-storage 来源: https://codeday.me/bug/20190710/1424864.html