- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 Angular 5 实现文件上传服务,我想就上传进度向用户提供一些反馈。我发现有几个页面建议使用 Angulars HttpClient
附带的 reportProgress
参数,但我无法让它工作。
我为我的所有 http 请求使用一个包装类,然后它执行一些逻辑,最后所有请求都以被调用的相同方法结束:
public request(request: HttpRequest<any>, options?: any): Observable<any> {
return this.httpClient.request(request.method, request.url, {
body: request.body,
headers: request.headers,
responseType: request.responseType,
...options
});
}
然后我将上传(发布)调用传递给它,使用 { reportProgress: true }
作为 options
。这根本不起作用,请求上没有任何改变。所以我怀疑,我实际上需要在 HttpRequest 构造函数中使用 reportProgress
参数来使其工作并相应地更改我的代码:
public request(request: HttpRequest<any>, options?: any): Observable<any> {
return this.httpClient.request(
new HttpRequest(request.method, request.url, request.body, {
headers: request.headers,
responseType: request.responseType,
...options
})
);
}
这导致了更奇怪的行为,现在无论我的选项是什么样的,我总是只收到 {type: 0}
作为请求的响应。
我在监督什么?我使用的是 Angular 5.1.1,现在我真的有点困惑。
所以举一个明确的例子,现在我收到了这两个 HttpRequests 的相同响应:
{
"url":"http://127.0.0.1:8888/test",
"body":{
"data":"testdata"
},
"reportProgress":false,
"withCredentials":false,
"responseType":"json",
"method":"POST",
"headers":{ some-headers ... }
}
和这个请求:
{
"url":"http://127.0.0.1:8888/api/pages",
"body":{
"pageUrl":"http://localhost:1234/"
},
"reportProgress":true,
"withCredentials":false,
"responseType":"json",
"method":"POST",
"headers":{ some-headers ... }
}
最佳答案
与 {reportProgress: true} 一起,您需要发送 {observe:“事件”
this.httpClient.post(environment.uploadDocument, file, { reportProgress: true, observe: 'events' })
.subcribe(data =>{
if (data['type'] === HttpEventType.UploadProgress) {
console.log('loaded ', data['loaded'], ' total -', data['total']);
}
})
关于angular - HttpRequest 和 reportProgress 不起作用或弄乱了我的请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49860324/
我有一个包含循环的后台工作线程。对于每次迭代,我想更新一个文本框,向用户显示正在发生的事情的日志。例如,如果用户正在抓取 200 个网站的标题,它会说: 抓取 site1.net抓取的 site2.n
如何将多个参数传递给 ReportProgress方法?我正在遵循本指南:MSDN创建一个进度条。我的代码如下所示。 MainWindow.xaml public User User { get; s
我想在 UI 中显示从 BackgroundWorker 到 ProgressBar 的进度。我不明白的是为什么 BackgroundWorker 的 ReportProgress 函数采用 Int3
我有一个 BackgroundWorker,它以 1 秒的间隔监视文件夹中的文件。如果它找到文件,那么它会为每个找到的文件引发 ReportProgress(0, fileName)。 在主线程上,我
我有 .NET 4.5 Windows Forms 应用程序,其中一种方法需要一段时间才能完成(这是一个 BulkCopy 函数,它加载大量数据并推送到 SQL)。 我想使用 BackgroundWo
有没有办法向Background Worker的ReportProgress方法提供Double变量类型,以便百分比以小数点显示? (例如 12.07%)或者我应该简单地将其作为 UserState
ReportProgress 方法有两个参数。一个是 int,一个是用户状态。为了某些处理目的,我将一些字符串参数传递到方法中,不需要 int。 有没有一种方法可以省略传递第一个 int 而没有冗余来
我是第一次设置后台 worker 。它主要在代码运行时工作,我的停止/取消按钮在工作。但是,我也在尝试报告更新进度条的进度,但我根本无法触发它。 我从运行此代码的按钮点击开始代码: backgroun
我正在使用 Angular 5 实现文件上传服务,我想就上传进度向用户提供一些反馈。我发现有几个页面建议使用 Angulars HttpClient 附带的 reportProgress 参数,但我无
我已经就这个主题搜索了几天,但没有找到任何相关的内容。请记住,我仍在学习如何在 C# 中使用 BackgroundWorker 和多线程。 我在使用 ReportProgress 方法时遇到问题。这是
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { int
我正在开发一个 C# 项目,我有一个 Backgroundworker 来完成我的“昂贵工作”。 在我的“DoWork”中,我想通过“backgroundworker.ReportProgress(s
我有一个应用程序可以收集视频列表中的数据。我希望实时更新进度和文件名。我是否必须将检查这些文件的所有代码都放在 bw_DoWork 方法中? 目前我有这个方法,但是 bw.ReportProgress
下面选项1和2有什么区别? private void BGW_DoWork(object sender, DoWorkEventArgs e) { for (int i
这个问题在这里已经有了答案: Angular file upload progress percentage [duplicate] (6 个答案) 关闭 3 年前。 我正在使用 HTTP POST
我使用 DispatcherTimer 因为我需要每隔几分钟执行一次操作。在其中我调用一个 BackgroundWorker 来完成我的工作,然后使用附加到计时器的调度程序来更新我的 UI。我在想我得
我遇到了 Google 为 Unity3D 编辑器提供的 Google Play 游戏插件的问题。我刚刚将该插件包含在我的统一项目中,当我将应用程序构建到我的 Android 设备上时,我可以使用我的
我正在尝试使用 ReportProgress() 方法将一个 int 数组从 backgroundworker 线程发送到我的主线程。 现在,如果我尝试发送一个整数或一个字符串,它工作正常。但如果我尝
我是一名优秀的程序员,十分优秀!