Last active
February 15, 2017 20:19
-
-
Save Loiree/943810b517b93a2c5c165e7e57127a12 to your computer and use it in GitHub Desktop.
Загрузка на сервер одного файла
This file contains hidden or 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
form(action="file_upload" method="POST" enctype="multipart/form-data") | |
input(type="file" name="file") | |
button Отправить |
This file contains hidden or 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
var path = require('path'); | |
// MULTER | |
var multer = require('multer'); | |
// "Конфиг" для Multer'а | |
var storage = multer.diskStorage({ | |
destination: function (req, file, cb) { | |
// Папка загрузки | |
cb(null, 'uploads/'); | |
}, | |
filename: function (req, file, cb) { | |
// Имя файла | |
cb(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname)); | |
} | |
}); | |
var upload = multer({ storage: storage }); | |
// MULTER | |
module.exports = function(app) { | |
app.get('/', require('./home').get); // Просто загрузка страницы с формой | |
app.post('/file_upload', upload.single('file'), function(req, res, next) { | |
console.log(req.file.filename + " загружен"); | |
res.status(200).send(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment