Skip to content

Instantly share code, notes, and snippets.

@Peregg
Created April 16, 2018 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Peregg/247452e48a44c91a80f21672dc02d4fe to your computer and use it in GitHub Desktop.
Save Peregg/247452e48a44c91a80f21672dc02d4fe to your computer and use it in GitHub Desktop.
Quest upload yaw !
const express = require('express');
const router = express.Router();
const multer = require('multer');
const upload = multer({ dest: 'tmp/' });
const fs = require('fs');
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Upload a file yaw !' });
});
router.post('/monupload', upload.array('monfichier', 3), function (req, res, next) {
console.log(req.files);
for (let i = 0; i < req.files.length; i++) {
if (req.files[i].size > 3000000) {
res.send("Hey yaw ! Ya file is too big yaw !");
} else if (req.files[i].mimetype!== 'image/png') {
res.send("Hey yaw ! it's notta png yaw !");
} else {
fs.rename(req.files[i].path, 'public/images/' + req.files[i].originalname, function(err){
if (err) {
res.send('It\'s suck bro! Something\'s gone wrong yaw !');
} else {
res.send('Uploaded yaw !');
}
});
}
}
});
module.exports = router;
extends layout
block content
h1= title
p You can upload many files using the ctrl button yaw !
form(method='POST', enctype='multipart/form-data', action='monupload')
input(type='file', name='monfichier', multiple='')
button envoyer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment