Hapi.jsfile upload如何抓取文件,以便使用imageMagick命令行工具

我改变了代码来输出一个文件,而不是一个stream。 IT为我提供了tmppath,当我使用fs.readFile转换为string时,数据是

fileUpload=Resume_BrianInoa.pdf 

我发布一个文件到hapijs服务器这是我的路线处理post:

  server.route({ method: 'POST', path: '/convert', config: { payload: { output:'file', maxBytes:209715200, parse: false, allow: 'application/x-www-form-urlencoded' }, handler:function (request, reply) { console.log('path : ' + request.payload.path); // request.payload["fileUpload"].pipe(fs.createWriteStream("test")); fs.readFile(request.payload.path, function (err, data) { if(err) console.error(err); else console.log(data.toString()); // I want to rewrite the file to a new folder here // Then convert it using imageMagick's command line tool // var newPath = __dirname + "/uploads/" + "newFile.txt" ; // fs.writeFile(newPath, data, function (err) { // console.log(err); // reply('done'); // }); }); } }, 

这是我的request.payload

 path : /tmp/1415580285921-24240-2cc7987f4fd124ac 

我其实检查我的/ tmp /文件夹,并打开它唯一的文件

的/ tmp / 1415580285921-24240-2cc7987f4fd124ac

已经是fileUpload = Resume_BrianInoa.pdf文件没有得到正确上传

我的表单的html代码

 <form action="./convert" method="post"> <input type="file" name="fileUpload" id="fileUpload" enctype="multipart/form-data" class="form-control"> <button class="btn">Submit</button> </form> 

只是总结你的HTML应该是这样的 –

 <form action="./convert" method="POST" enctype="multipart/form-data"> <input type="file" name="fileUpload" id="fileUpload" class="form-control"> <button class="btn">Submit</button> </form> 

和你的hapi路线

  server.route({ method: 'POST', path: '/convert', config: { payload: { output: 'file', maxBytes: 209715200, //allow: 'multipart/form-data', parse: true //or just remove this line since true is the default }, handler:function (request, reply) { console.log('fileUpload path : ' + request.payload.fileUpload.path); } }, });