javascript – Firebase存储随机返回存储/取消
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – Firebase存储随机返回存储/取消,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1934字,纯文字阅读大概需要3分钟。
内容图文
我收到一条错误,指出用户取消了上传,我从控制台中的单个上传中收到了三个错误(上传文件时来自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_
:
空值
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
是取消可观察性的罪魁祸首.
解:
<ng-container *ngIf="(uploadPercent$| async); let uploadPercent">
<mat-progress-bar mode="determinate" *ngIf="uploadPercent !== 100" [value]="uploadPercent"></mat-progress-bar>
</ng-container>
内容总结
以上是互联网集市为您收集整理的javascript – Firebase存储随机返回存储/取消全部内容,希望文章能够帮你解决javascript – Firebase存储随机返回存储/取消所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。