Created
August 18, 2017 12:12
-
-
Save lmiller1990/3f1756efc07e09eb4f44e20fdfce30a4 to your computer and use it in GitHub Desktop.
This file contains 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
<!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> |
This file contains 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 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