我遇到了一个错误,提示上传被用户取消,并且在控制台上出现了三个相同的错误(来自Firebase存储的文件上传)。我无法看到代码中如何进行取消操作(假设因为它声明是由用户取消的,那么它应该在代码中)。
完整的错误信息来自Chrome控制台: "storage/canceled" code_: "storage/canceled" message: "Firebase Storage:用户取消了上传/下载。" message_: "Firebase存储:用户取消了上传/下载。" name(...): name_: "FirebaseError" serverResponse: null serverResponse_: null
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控制台: "storage/canceled" code_: "storage/canceled" message: "Firebase Storage:用户取消了上传/下载。" message_: "Firebase存储:用户取消了上传/下载。" name(...): name_: "FirebaseError" serverResponse: null serverResponse_: null
Firebase存储:展示一些上传工作(即使我出现了错误):
![Firebase Randomly works](https://istack.dev59.com/BhHw1.webp)