上传进度——请求 [英] Upload Progress — Request

查看:17
本文介绍了上传进度——请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Request 上传文件.

I'm uploading a file using Request.

req = request.post url: "http://foo.com", body: fileAsBuffer, (err, res, body) ->
    console.log "Uploaded!"

我如何知道实际上传了多少数据?是否有一些我可以订阅的事件,或者是否有我可以轮询的 request 的属性?

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?

推荐答案

我需要处理我的另一个项目的上传进度.

I needed a handle on the upload progress for yet another project of mine.

我发现你可以轮询 requestconnection._bytesDispatched 属性.

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,请改为轮询 r.req.connection.socket._bytesDispatched.

Note: If you were piping to r, poll r.req.connection.socket._bytesDispatched instead.

这篇关于上传进度——请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆