java - Sending an image from Python to NodeJS + Express via POST -
on front end device have opencv running python. send computed image server further processing. problem can't decode image express.
i send image front end device thusly (in python 2.7):
import requests url = "http://10.1.10.194:3000" files ={'image':open('testimg.jpg','rb')} r = requests.post(url,files=files)
this sends post command express app, hears post request , following:
app.post('/', function(request, respond) { console.log(request.headers) var image = request.body fs.writefile('test.jpg', image, function(err){ if (err) throw err console.log('file saved.'); }); respond.end('thanks'); });
i know i'm correctly receiving picture, header correctly lists filesize, when print image, it's text file [object object].
output of express app here:
{ host: '10.1.10.194:3000', 'content-length': '14551', 'accept-encoding': 'gzip, deflate', accept: '*/*', 'user-agent': 'python-requests/2.9.1', connection: 'keep-alive', 'content-type': 'multipart/form-data; boundary=e664d9584c484962bfe4d1577bd4d91b' } post / 200 15.754 ms - - file saved.
my express app loading body-parser, can't seem figure out how raw data out of request.body. advice welcome. thanks!
did try using multer module ?
var multer = require('multer'); var upload = multer({dest: './uploads/'}); app.post('/', upload.single('file'), function(request, respond) { if(request.file) console.log(request.file); }
Comments
Post a Comment