简体   繁体   English

Express Node.js-如何将request.files传递到另一个POST请求

[英]Express Nodejs - How to pass request.files to another POST request

I have a page where user uploads files and are passed to Node API which does some operations like database insert and finally has to send the files to another node rest API for virus check. 我有一个页面,用户在该页面上载文件,并将其传递到Node API,Node API执行一些操作(如数据库插入),最后必须将文件发送到另一个Node Rest API进行病毒检查。

I can see file content and attributes in req.files in the first API call but struggling to pass req.files to another node API URL using request.post . 我可以在第一个API调用中看到req.files中的文件内容和属性,但是很难使用request.postreq.files传递到另一个节点API URL。

 var uploadFile= function(req, res) {
       var files = req.files.upload;
Async.series(
        [ function (callback) {..},
          function (callback){viruscheck(files,callback);}
....

//viruscheck method
var viruscheck= function(files, callback) {
request.post({url: "http://loclahost:1980/viruscheck/upload.json", 

                qs: {
                    ..
                }, 
                headers: {'enctype-type': 'multipart/form-data'},
                form:{
                    upload:files
                }
        },function(error, response, body){
            if(error) {
                console.log(error);
                callback(error)
            } else {
                console.log(response.statusCode, body);
                callback()
            }
        });
}

In API http://loclahost:1980/viruscheck/upload.json I see file content in body rather than req.files . 在API http:// loclahost:1980 / viruscheck / upload.json中,我在正文中看到文件内容,而不是req.files

How can I get the files in request.files in my second API call? 如何在第二个API调用中获取request.files中的文件?

Use: 采用:

headers: {'Content-Type': 'multipart/form-data'},

Instead of: 代替:

headers: {'enctype-type': 'multipart/form-data'},

enctype is an HTML form thing. enctype是HTML形式的东西。

See this answer for more: Uploading file using POST request in Node.js 有关更多信息,请参见此答案: 在Node.js中使用POST请求上传文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM