Skip to content

Instantly share code, notes, and snippets.

@Loiree
Last active February 15, 2017 20:19
Show Gist options
  • Save Loiree/943810b517b93a2c5c165e7e57127a12 to your computer and use it in GitHub Desktop.
Save Loiree/943810b517b93a2c5c165e7e57127a12 to your computer and use it in GitHub Desktop.
Загрузка на сервер одного файла
form(action="file_upload" method="POST" enctype="multipart/form-data")
input(type="file" name="file")
button Отправить
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