0

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)

3
  • 1
    Does it not work? How do you know? Read about How to Ask Commented Apr 6, 2017 at 21:50
  • Thanks I updated question Commented Apr 6, 2017 at 22:06
  • Possible duplicate of Node Multer unexpected field Commented Apr 6, 2017 at 22:15

1 Answer 1

1

in node.js change upload.array() to upload.array('file')

and in python :

files = {'file': ('test_file', open(filePath, 'rb'))} to

files = {'file':open(filepath,'rb')}

check answer from this post Get image sent from post in node.js

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.