I got some help here on the nodejs side: Extract file from POST request nodejs
I am new to node, and I am having problems getting this file node.js (Server PC)
var express = require('express');
var bodyParser = require('body-parser');
var multer = require('multer')
var app = express();
var upload = multer({ dest: 'uploads/' })
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
/* POST commands */
app.post('/upload', upload.array(), function (req, res, next) {
console.log("I AM HERE");
})
python script (Client PC)
files = {'file': ('test_file', open(filePath, 'rb'))}
r = requests.post("http://192.168.2.39:3000/upload", files=files)
What am I doing wrong here? thanks
I am getting error 500,
Unexpected field
Error: Unexpected field at makeError (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\multer\lib\make-error.js:12:13) at wrappedFileFilter (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\multer\index.js:40:19) at Busboy.<anonymous> (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\multer\lib\make-middleware.js:114:7) at emitMany (events.js:127:13) at Busboy.emit (events.js:201:7) at Busboy.emit (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\busboy\lib\main.js:38:33) at PartStream.<anonymous> (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\busboy\lib\types\multipart.js:213:13) at emitOne (events.js:96:13) at PartStream.emit (events.js:188:7) at HeaderParser.<anonymous> (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\dicer\lib\Dicer.js:51:16)
in node.js change
upload.array()
toupload.array('file')
and in python :
files = {'file': ('test_file', open(filePath, 'rb'))}
tocheck answer from this post Get image sent from post in node.js