Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var router = express.Router();
- const multer = require('multer');
- const upload = multer({ dest: 'tmp/' });
- const fs = require('fs');
- /* GET users listing. */
- router.get('/', function (req, res, next) {
- res.render('upload', { title: 'Upload Files' })
- });
- router.post('/', upload.array('myfile'), function (req, res) {
- for (let i = 0; i <= req.files.length - 1; i++) {
- if (req.files[i].mimetype === 'image/png' && req.files[i].size < 3145728) {
- fs.rename(req.files[i].path, 'public/images/' + req.files[i].originalname, function (err) {
- if (err) { res.sendStatus(500) }
- })
- }
- else { console.log(req.files[i].originalname + ' non accepte') }
- }
- res.sendStatus(200);
- })
- module.exports = router;
Add Comment
Please, Sign In to add comment