req.files creates zero, and now req.body is also empty. I looked through all the answers here and cannot find much. Unfortunately, the documentation for the cartoon was not enough, so I hope someone went through what I now know what is happening.
My router.js file:
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();
...
...
...
...
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 quite sure what is wrong with this, I originally had it as upload.single ("image"), but it did not work, so who knows.
Here is my form of jade that needs to be sent if someone 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