node.js - 在node js中接收多部分表单数据

标签 node.js restify

我正在尝试将多部分表单数据从 postman 发送到我的nodejs Restify 服务器。但 request.files 未定义。

下面是我的代码和 postman 的屏幕截图。

//代码

var restify = require('restify');
var os = require('os');


var server = restify.createServer({
    name: 'New App',
    version: '1.0.0'
});

server
    .use(restify.acceptParser(server.acceptable))
    .use(restify.fullResponse())
    .use(restify.bodyParser({mapParams: true, 
        mapFiles: true,
        keepExtensions: true,
        uploadDir: os.tmpdir()
    }));

server.post({path: '/api/image', version: '1.0.0'},controllers.image.addImage);

exports.addImage = function (req, res, next) {

    console.log("Files : "+req.files);
}

输出:

文件:未定义

截图:

/image/0hTX0.png

最佳答案

您可以使用restify-multipart-body-parser - 请参阅:

关于node.js - 在node js中接收多部分表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45282153/

相关文章:

javascript - 无法启动Azure中托管的nodejs Web api

node.js - 有没有办法用restify在控制台中记录每个请求?

javascript - 获取 restify REST API 服务器以支持 HTTPS 和 HTTP

node.js - 将 Webpack 开发服务器与 PHP 应用程序一起使用

mongodb - (Node.js/Express.js) 错误 : Schema hasn't been registered for model "document"

javascript - 在 Couchdb ( iriscouch ) POST 请求中添加新文档失败,状态为 500

javascript - 使用 NodeJS 实现自动化

node.js - 将 everyauth 与 restify 一起使用

node.js - 启用 CORS 的服务器不拒绝请求

node.js - 我应该为我的 Node.js 应用程序选择哪种 Azure 服务?