上传进度 - 请求 [英] Upload Progress — Request
本文介绍了上传进度 - 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要使用 请求
上传文件。
I'm uploading a file using Request
.
req = request.post url: "http://foo.com", body: fileAsBuffer, (err, res, body) ->
console.log "Uploaded!"
如何知道实际上上传了多少数据?是否有一些事件可以订阅,或者是否有请求
的属性,我可以轮询?
How do I know how much data has actually been uploaded? Is there some event that I can subscribe to or is there a property of the request
that I can poll?
如果没有,上传数据的最佳方法是什么,并知道已上传了多少?
If none, what would be the best approach to upload data and know how much has been uploaded?
推荐答案
我发现的是你可以查询请求
'的上传进度。
What I found out is that you can poll the request
's connection._bytesDispatched
property.
例如:
r = request.post url: "http://foo.com", body: fileAsBuffer
setInterval (-> console.log "Uploaded: #{r.req.connection._bytesDispatched}"), 250
注意:如果分别是 r
,poll r.req.connection.socket._bytesDispatched
。
Note: If you were piping to r
, poll r.req.connection.socket._bytesDispatched
instead.
这篇关于上传进度 - 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文