angular - Angular中的渐进式上传文件
问题描述
在angular.io站点中有一个上传文件的上传服务,但它不是完整的类 是否有一个丰富的类示例,用于上传具有最佳功能和模式的数据,包含渐进式错误处理和设置标题等...?建议的角度类包含以下代码:
private getEventMessage(event: HttpEvent<any>, file: File) {
switch (event.type) {
case HttpEventType.Sent:
return `Uploading file "${file.name}" of size ${file.size}.`;
case HttpEventType.UploadProgress:
// Compute and show the % done:
const percentDone = Math.round(100 * event.loaded / event.total);
return `File "${file.name}" is ${percentDone}% uploaded.`;
case HttpEventType.Response:
return `File "${file.name}" was completely uploaded!`;
default:
return `File "${file.name}" surprising upload event: ${event.type}.`;
}
}
解决方案
推荐阅读
- java - 如何在单页应用程序中使用 keycloak
- javascript - Jquery - 获取单击的 DIV 元素的 ID
- c# - 我可以在.net core 中为每个区域设置一个默认页面吗?
- wait - 如何等待一组 slurm 工作中的一个工作完成
- html - 根据某些条件对齐按钮
- sql - 哪些表用于获取 OIM 中的编排信息?
- javascript - 如何在 Javascript 中访问从 Django 应用程序发送的上下文变量
- matlab - Matlab:带有函数句柄的 jsconencode
- java - 如何使这个复杂的 if-else 语句在 Kotlin 中可维护
- json - 如何将 SPARQL 查询结果作为 JSON 对象查看?