Instantly share code, notes, and snippets.

Embed
What would you like to do?
upload
var express = require('express');
var router = express.Router();
var multer = require('multer');
var upload = multer({
dest: 'tmp/'
});
var fs = require('fs');
/* GET home page. */
router.get('/', function (req, res, next) {
res.render('index', {
title: 'Express'
});
});
router.get('/upload', function (req, res, next) {
res.render('upload', {
title: 'Express'
});
});
router.post('/uploaddufichier', upload.array('monfichier'), function (req, res, next) {
console.log("file" + req.files + req.files);
for (let i = 0; i < req.files.length; i++) {
if (req.files[i].mimetype !== 'image/png') {
res.send('I don\'t have a clue!');
} else if (req.files[i].size > 3000000) {
res.send('I don\'t have a clue!');
} else {
fs.rename(req.files[i].path, 'public/images/' + req.files[i].originalname, function (err) {
if (err) {
res.send('problème durant le déplacement');
} else {
res.send('Fichier uploadé avec succès');
}
})
}
}
});
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment