节点服务器和python客户端文件上传

时间:2015-11-06 16:31:14

标签: python node.js

我有一个使用python客户端(请求库)和节点服务器(multer模块)的场景。

在Python方面 - >

filepath = "./temp/test.step"
temp = {'file': ('test_file', open(filepath, 'rb'))}
r2 = requests.post('http://localhost:4041/upload', files = temp)
print("File Upload Status: " + r2.text)

在节点端 - >

var multer  = require('multer');
var upload = multer({ dest: __dirname + '/uploads/' });
app.post('/upload', upload.single('test_file'), function (req, res ) {
   if (!req.file) {
      return res.sendStatus(400);
   }
   else {
       console.log(req.files);
       return res.sendStatus(200);
   }
})

回归 - >错误:意外字段

提前感谢任何建议。

以下是我上传文件的错误:

Error: Unexpected field
at makeError (/PATH2DIR/python_node_upload/node_modules/multer/lib/make-error.js:12:13)
at wrappedFileFilter (/PATH2DIR/python_node_upload/node_modules/multer/index.js:39:19)
at Busboy.<anonymous> (/PATH2DIR/python_node_upload/node_modules/multer/lib/make-middleware.js:112:7)
at Busboy.emit (events.js:118:17)
at Busboy.emit (/PATH2DIR/python_node_upload/node_modules/multer/node_modules/busboy/lib/main.js:31:35)
at PartStream.<anonymous> (/PATH2DIR/python_node_upload/node_modules/multer/node_modules/busboy/lib/types/multipart.js:209:13)
at PartStream.emit (events.js:107:17)
at HeaderParser.<anonymous> (/PATH2DIR/python_node_upload/node_modules/multer/node_modules/busboy/node_modules/dicer/lib/Dicer.js:51:16)
at HeaderParser.emit (events.js:107:17)
at HeaderParser._finish (/PATH2DIR/python_node_upload/node_modules/multer/node_modules/busboy/node_modules/dicer/lib/HeaderParser.js:70:8)

0 个答案:

没有答案