Skip to content

Instantly share code, notes, and snippets.

@lmiller1990
Created August 18, 2017 12:12
Show Gist options
  • Save lmiller1990/3f1756efc07e09eb4f44e20fdfce30a4 to your computer and use it in GitHub Desktop.
Save lmiller1990/3f1756efc07e09eb4f44e20fdfce30a4 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="/photo" method="POST" enctype="multipart/form-data">
<input type="file" name="userPhoto">
<input type="submit" value="Upload">
</form>
</body>
</html>
var express = require('express');
var multer = require('multer');
var app = express();
var path = './uploads';
app.use(express.static('public'))
var storage = multer.diskStorage({
destination: path,
filename: function (req, file, callback) {
callback(null, file.fieldname + '-' + Date.now());
}
});
var upload = multer({ storage : storage }).single('userPhoto');
app.post('/photo',function(req,res){
console.log('Im in post , outside upload'+path);
upload(req,res,function(err) {
console.log(err, 'Im in post , inside upload'+path);
if(err) {
return res.end('Error uploading file.');
}
res.end('File is uploaded'+path);
console.log('File is uploaded'+path);
});
});
app.listen(3000,function(){
console.log('Working on port 3000');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment