I want to upload some files on the local server.I am using multer for uploading.I am stuck as after posting request the file is not uploaded. Can Someone guide me, what the problem is or please tell any other way to do it.
My Index.js is -
var routes = {
views: importRoutes('./views'),
};
var multer = require('multer');
var upload = multer({ dest: 'public/' });
// Setup Route Bindings
exports = module.exports = function (app) {
// Views
app.get('/', routes.views.index);
app.get('/students',routes.views.students);
app.get('/upload',routes.views.fileUpload);
app.post('/upload',upload.single('userFile'),routes.views.fileUpload);
// NOTE: To protect a route so that only admins can see it, use the requireUser middleware:
// app.get('/protected', middleware.requireUser, routes.views.protected);
};
and my Upload.pug is -
extends ../layouts/default
block content
form(method="post", enctype='multipart/form-data')
input(type="file", name="userFile")
input(type="submit" ,value="uploadFile",name="submit")
via Aakash Madan
No comments:
Post a Comment