获取要在服务器上解析的文件数据

时间:2017-09-14 19:47:18

标签: javascript node.js file file-upload buffer

我正在尝试上传一个简单的pdf文件。

我使用express-fileupload来完成将文件上传到服务器的工作,这里一切正常,问题到了我需要用我收到的缓冲区创建文件,基本上我需要存储文件在服务器上。我怎么能这样做?

目前在我的服务器中我收到了这些数据:

{ name: 'sda.pdf',
  data: <Buffer 25 50 44 46 2d 31 2e 35 0d 25 e2 e3 cf d3 0d 0a 31 20 30 20 6f 62 6a 0d 3c 3c 2f 4d 65 74 61 64 61 74 61 20 32 20 30 20 52 2f 4f 43 50 72 6f 70 65 72 ... >,
  encoding: '7bit',
  mimetype: 'application/pdf',
  mv: [Function: mv] }

我在上传路线上记录数据:

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

任何帮助?

1 个答案:

答案 0 :(得分:0)

您可以在mv对象上看到express-fileupload函数。使用此功能将文件放在服务器上所需的位置。 (来自express-fileupload自述文件)

sampleFile.mv('/somewhere/on/your/server/filename.jpg', function(err) {
    if (err)
        return res.status(500).send(err);
    res.send('File uploaded!');
});