I'm trying to upload a file with connect-multiparty on my api but I can't make it works.
Here my code (a sample, because my api have a lot of working routes):
var express = require('express');
var bodyParser = require('body-parser');
var multipart = require('connect-multiparty');
var app = express();
var multipartMiddleware = multipart({ uploadDir: './imagesPath' });
// Define middleware
app.use(bodyParser.urlencoded({ extended: true })); // Support encoded bodies
app.use(bodyParser.json()); // Support json encoded bodies
var router = express.Router(); // Get an instance of the express Router
router.post('/testFileUpload', multipartMiddleware, function(req, res) {
console.log(req.body, req.files);
// Some other code
});
When I try to upload a file both req.body and req.files are empty {}
I know Body-Parser doesn't support multipart/form-data anymore so I'm trying to find a way to use it with another package but with no success so far.
I've tried with busboy, connect-busboy, multer, formidable, express-formidable, express-fileupload but everytime req.files is undefined, so I kinda feel I've make some progress with connect-multiparty by having req.files empty.
I've seen some topics with similar problems like this one, this one or this one but unfortunatly none of those helped me.
In client side I'm using Advanced REST Client and Postman.
Any ideas what I'm doing wrong ?