req.files is producing null and now req.body is also blank. I've searched through all the answers here and can't find much. Unfortunately, the multer documentation was pretty lacking, so hopefully someone has gone through what I am right now and knows what is happening.
My router.js file is this:
var express = require('express');
var request = require('request');
var mid = require('../middleware');
var busboy = require('connect-busboy');
var fs = require('fs');
var multer = require('multer');
var upload = multer({dest: '../public/images/blog'});
var User = require('../data/models/user');
var router = express.Router();
...
...
...
...
/* POST saveblog router. */
router.post('/saveBlog', upload.any(),function(req, res, next) {
console.log(req.body, 'Body');
console.log(req.files, 'files');
var title = req.body.titleInput;
var body = req.body.bodyInput;
request.post('http://' +req.headers.host + '/api/blog', {json: {body: body, title: title, userId: req.session.userId}},
function(err, httpResponse, body) {
if (err) {
console.error('error posting blog');
}
console.log('Blog Post successfully uploaded');
});
return res.redirect('/blog');
});
module.exports = router;
So I'm not totally sure what's wrong with that, I originally had it as upload.single('image') but that didn't work either so who knows.
Here is my jade form to be submitted, if anyone can help but doesn't like jade I'm sure I can find a quick converter for it.
form(action='saveBlog', enctype='multipart/form-data', method='post')
h1 New Blog Post
fieldset(data-role='')
label(for='title') Title
input(id='titleInput', name='titleInput', type='text', value='', placeholder='Your Title', require='true').form-control
label(for='image') Your Title Image
input(id='image',name='image', type='file', accept='image/*')
br
label(for='body') Your Article (Box is resizable)
textarea(id='mytextarea', name='bodyInput').form-control
input(type='submit', value='Post your Article').btn.btn-primary