我收到一条错误消息,指出上传已被用户取消,并且我在控制台中的一次上传中收到三个错误(上传文件时来自 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 存储:用户取消了上传/下载。” 名称 : (...) 名称_ : “火力地堡错误” 服务器响应 : 无效的 服务器响应_ : 空
最佳答案
我自己也遇到了这个错误:
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
是取消 observable 的罪魁祸首。
解决方法:
<ng-container *ngIf="(uploadPercent$ | async); let uploadPercent">
<mat-progress-bar mode="determinate" *ngIf="uploadPercent !== 100" [value]="uploadPercent"></mat-progress-bar>
</ng-container>
关于javascript - Firebase 存储随机返回存储/取消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52761303/