Created
March 28, 2018 17:50
-
-
Save nastajus/e619ea3a3d1ab1632252efa8f2c0f164 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
const express = require('express'); | |
const multer = require('multer'); | |
const ejs = require('ejs'); | |
const path = require('path'); | |
//const bodyParser = require('body-parser'); | |
const port = process.env.PORT || 3004; | |
const app = express(); | |
const storage = multer.diskStorage({ | |
destination: './public/uploads/', | |
filename: function(req, file, cb){ | |
cb(null, file.fieldname + Date.now() + path.extname(file.originalname)); | |
} | |
}); | |
const upload = multer({ storage: storage }); | |
app.set('view engine', 'ejs'); | |
app.use(express.static('./public')); | |
//below are attempts to somehow "bind middleware" as I understand it, no difference | |
//app.use(upload); | |
//app.use(multer({dest:'./public/uploads/'}).single('file')); | |
app.get('/', (req, res) => res.render('index')); | |
app.post('/upload', upload.single('myImage'), (req, res) => { | |
if(req.err){ | |
res.render('index', {msg: err}); | |
} | |
else { | |
console.log(req.file); | |
res.send('test'); | |
} | |
}); | |
app.listen(port, function () { | |
console.log('listening on port ', port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this executes successfully in alternate IDE vscode, but my preferred IDE webstorm pukes at both
req.err
andreq.file
.seems like i have several problems rolled into one, that i'm trying to untangle.