作者:当初 | 来源:互联网 | 2022-12-02 15:11
我收到一条错误消息,指出用户取消了上传,并且从控制台中的一次上传中收到了三个错误(上传文件时,来自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存储:用户取消了上载/下载”。message _:“ Firebase存储:用户取消了上载/下载。” name:(...)name_:“ FirebaseError” serverResponse:null serverResponse_:null
Firebase存储:显示某些上载有效(即使出现错误):