use*_*415 5 javascript firebase firebase-storage
我收到一条错误消息,指出用户取消了上传,并且从控制台中的一次上传中收到了三个错误(上传文件时,来自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");
})
);
}
Run Code Online (Sandbox Code Playgroud)
chrome控制台的完整错误:“存储/取消”代码_:“存储/取消”消息:“ Firebase存储:用户取消了上载/下载”。message _:“ Firebase存储:用户取消了上载/下载。” name:(...)name_:“ FirebaseError” serverResponse:null serverResponse_:null
我自己刚刚遇到了这个错误:
FirebaseStorageError {code_: "storage/canceled", message_: "Firebase Storage: User canceled the upload/download.", serverResponse_: null, name_: "FirebaseError"}
Run Code Online (Sandbox Code Playgroud)
我原来的看法
<mat-progress-bar mode="determinate" *ngIf="(uploadPercent | async) == 0" [value]="uploadPercent | async"></mat-progress-bar>
Run Code Online (Sandbox Code Playgroud)
| async
Run Code Online (Sandbox Code Playgroud)
是取消 observable 的罪魁祸首。
解决方案:
<ng-container *ngIf="(uploadPercent$ | async); let uploadPercent">
<mat-progress-bar mode="determinate" *ngIf="uploadPercent !== 100" [value]="uploadPercent"></mat-progress-bar>
</ng-container>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
389 次 |
| 最近记录: |