Multipart上传文件引发错误

时间:2018-02-21 06:30:33

标签: node.js express multer

我一直在尝试从浏览器上传一个csv文件来表达js然后从那里发送一个post调用到另一个url来使用multipart上传相同的文件。但它会抛出错误,如下所示

Argument error, options.multipart.
Error: Argument error, options.multipart.
    at Multipart.isChunked (d:\avx_node_poc\avx-webApp\node_modules\request\lib\multipart.js:21:32)
    at Multipart.onRequest (d:\avx_node_poc\avx-webApp\node_modules\request\lib\multipart.js:104:22)
    at Request.multipart (d:\avx_node_poc\avx-webApp\node_modules\request\request.js:1270:19)
    at Request.init (d:\avx_node_poc\avx-webApp\node_modules\request\request.js:406:10)
    at new Request (d:\avx_node_poc\avx-webApp\node_modules\request\request.js:128:8)
    at request (d:\avx_node_poc\avx-webApp\node_modules\request\index.js:53:10)
    at d:\avx_node_poc\avx-webApp\routes\index.js:231:5
    at Layer.handle [as handle_request] (d:\avx_node_poc\avx-webApp\node_modules\express\lib\router\layer.js:95:5)
    at next (d:\avx_node_poc\avx-webApp\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (d:\avx_node_poc\avx-webApp\node_modules\express\lib\router\route.js:112:3)

以下是快递代码

const express = require('express');
const http = require('http');
const router = express.Router();
const request = require('request');
const multer  = require('multer');
const upload = multer();

const prop = {
    protocol: "http:",
    host: '192.168.138.171',
    port: 7300
};

/* uploadAndValidateUsers call */
router.post('/uploadAndValidateUsers', upload.single('userFile'),function(req, res, next) {
    console.log(req.file);
    request({
        url: prop.protocol + "//" + prop.host + ":" + prop.port + "/avxui/" + req.url,
        headers: {
            "Cookie": req.headers['cookie'],
            "Content-Type": req.headers['content-type']
        },
        method: req.method,
        multipart: req.file
    }).pipe(res);
});

module.exports = router;

1 个答案:

答案 0 :(得分:0)

您错过了deststorage选项

var upload = multer({ dest: 'uploads/' })

multer options