如何下载nodejs服务器上传的文件

时间:2016-11-03 17:00:24

标签: node.js perl httpresponse perl-module

我正在node.js服务器上传文件。下面是它的代码。

  var formData = new FormData();
  formData.append('part1', fs.createReadStream(file1));
  formData.append('part2', fs.createReadStream(file2));

  formData.submit({
    host: 'xyz',
    port: 4354,
    path: '/handler',
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/mixed; boundary=' + formData.getBoundary()
    }
  }, function (error, response, body) {

    if (!error && response.statusCode === 200) {
     // Success case
    } else {
     // Failure case
    }

  });

现在,如何在perl服务器中下载该文件???

尝试HTTP :: Response的decode_content()方法。它正在记录响应,如下所示。下面我找不到更简单的方法来下载文件。

 ----------------------------401882132761579819223727^M
Content-Disposition: form-data; name="fileContent"; filename="filepath"^M
Content-Type: application/octet-stream^M
^M   
FileContent FileContent FileContent FileContentFileContentFileContent
FileContentFileContentFileContentFileContentFileContentFileContentFileContent
FileContentFileContentFileContentFileContentFileContentFileContentFileContent  
----------------------------401882132761579819223727--^M

1 个答案:

答案 0 :(得分:0)

使用Perl的MIME :: Parser

解决了这个问题
    cell.selectionStyle = .none

$ part1和$ part2将是类型MIME::Entity对象,并根据我的要求使用合适的方法来阅读其内容。