-
npm install
-
node app.js
-
In browser open url "http://localhost:8000"
-
Select file to upload.
-
Click upload.
-
The file is saved as "filename.jpg."
Last active
May 17, 2016 00:31
-
-
Save scottgwald/3a55b3fae49e408a0b4084895b6710ea 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
var express = require('express'); | |
var fileUpload = require('express-fileupload'); | |
var app = express(); | |
// default options | |
app.use(fileUpload()); | |
app.use(express.static('.')); | |
app.post('/upload', function(req, res) { | |
var sampleFile; | |
if (!req.files) { | |
res.send('No files were uploaded.'); | |
return; | |
} | |
sampleFile = req.files.sampleFile; | |
sampleFile.mv('./filename.jpg', function(err) { | |
if (err) { | |
res.status(500).send(err); | |
} | |
else { | |
res.send('File uploaded!'); | |
} | |
}); | |
}); | |
app.listen(8000, function () { | |
console.log('Example app listening on port 8000!'); | |
}); |
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
<html> | |
<body> | |
<form ref='uploadForm' | |
id='uploadForm' | |
action='http://localhost:8000/upload' | |
method='post' | |
encType="multipart/form-data"> | |
<input type="file" name="sampleFile" /> | |
<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
{ | |
"dependencies" : { | |
"express": "latest", | |
"express-fileupload": "latest" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment