Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Upload a file using ExpressJS+Multer

var express = require('express');
var router = express.Router();
const multer  = require('multer');

const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'uploads/')
  },
  filename: function (req, file, cb) {
    cb(null, file.originalname)
  }
})
const upload = multer({storage: storage})

router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

router.post('/profile', upload.single('avatar'), function (req, res, next) {
})


module.exports = router;
Source by expressjs.com #
 
PREVIOUS NEXT
Tagged: #Upload #file
ADD COMMENT
Topic
Name
3+5 =