Get image sent from post in node.js
<p>I need to use python to send an image through post and then download it on the node.js server side.</p>

<p>Python code:</p>

<pre><code>import requests
from PIL import Image
import json

url = 'http://127.0.0.1:8080/ay'
files = {'file': open('image.jpg', 'rb')}
r = requests.post(url, data = files)
</code></pre>

<p>Node.js code:</p>

<pre><code>var app = express();
app.use(bodyparser.json({ limit: '50mb' }));
app.use(bodyparser.urlencoded({ limit: '50mb', extended: true }));

app.post('/ay', function(req, res) {
    var base64Data = req.body.file
    require("fs").writeFile("out.png", base64Data, 'base64', function(err) {
        console.log(err);
    });

    res.send('done');
});
</code></pre>

<p>But I can't seem to download the file properly on the server so I'm wondering what format python uses to open images and how I can fix the node.js code so that it can properly download the image.</p>

<p>Edit: there were a few issues with the code, I'm trying to use multer now but can't seem to get it working.</p>

<p>Python code:</p>

<pre><code>import requests

url = 'http://127.0.0.1:8080/ay'
files = {'file': open('image.jpg', 'rb')}
r = requests.post(url, files = files)
</code></pre>

<p>Node.js code:</p>

<pre><code>var express = require('express');
var multer  = require('multer')
var upload = multer({ dest: 'uploads/' })
var app = express();

app.post('/ay', upload.single('avatar'), function (req, res, next) {
    console.log(req.file)
    res.send("done");
});

app.post('/ay', upload.array('photos', 12), function (req, res, next) {
    console.log(req.files)
    res.send("done");
});
</code></pre>

<p>I've tried both upload.single and upload.array but neither work.</p>