Created
April 16, 2018 13:46
-
-
Save Peregg/247452e48a44c91a80f21672dc02d4fe to your computer and use it in GitHub Desktop.
Quest upload yaw !
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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