跟踪Multer Node.js中文件上传的进度 [英] Tracking progress of file upload in multer nodejs

查看:421
本文介绍了跟踪Multer Node.js中文件上传的进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何跟踪文件上传到NodeJs服务器的进度.我正在服务器端使用multer来上传文件. ?

How to track progress of a file getting uploaded to NodeJs server .I am using multer in server side to upload files. ?

我是否需要向客户端发送某种信息,以便客户端获得上传进度,或者这是在内部完成的?客户可以跟踪其进度.

Do i need to send some kind of information to the client , So that client gets the upload progress OR this is done internally & client can track progress on its on.

下面是我用来上传文件的代码:

Below is the code i am using to upload file :

var multer = require('multer');
app.use(multer({dest:'./tmp',limits: {fileSize: 4*1024*1024}}).single('upload'));


router.post('/upload',function(req,res){
 console.log(req.file);
});

推荐答案

这是一个 answer (他建议使用 progress-stream ):

Here's an answer by LinusU at the project github's page (he suggests using progress-stream):

将要求与之对应,然后将其发送给multer.

Pipe req to that one and give it to multer.

    var p = progress()
    var upload = multer().single('file')

    req.pipe(p)
    p.headers = req.headers

    p.on('progress', _)
    upload(p, res, _)

这篇关于跟踪Multer Node.js中文件上传的进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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