Showing
5 changed files
with
64 additions
and
0 deletions
1 | +const express = require('express'); | ||
2 | +const fileUpload = require('express-fileupload'); | ||
3 | +const app = express(); | ||
4 | + | ||
5 | +//var aws = require('aws-sdk'); | ||
6 | +//aws.config.loadFromPath('./awsconfig.json'); | ||
7 | + | ||
8 | +//var BUCKET_NAME = 'intothegalaxy'; | ||
9 | +//var s3 = new aws.S3(); | ||
10 | + | ||
11 | + | ||
12 | +function uploadFile(file, res) { | ||
13 | + | ||
14 | + // Use the mv() method to place the file somewhere on your server | ||
15 | + file.mv('./upload/' + file.name, function(err) { | ||
16 | + if (err) | ||
17 | + return res.status(500).send(err); | ||
18 | + | ||
19 | + res.send('File uploaded!'); | ||
20 | + }); | ||
21 | + | ||
22 | + | ||
23 | +} | ||
24 | + | ||
25 | +// default options | ||
26 | +app.use(fileUpload()); | ||
27 | + | ||
28 | +app.post('/', function(req, res) { | ||
29 | + if (!req.files) | ||
30 | + return res.status(400).send('No files were uploaded.'); | ||
31 | + uploadFile(req.files.file, res); | ||
32 | +}); | ||
33 | + | ||
34 | +app.get('/:fileName', function(req, res){ | ||
35 | + var file = __dirname + '/upload/' + req.params.fileName; | ||
36 | + res.download(file); // Set disposition and send it. | ||
37 | +}); | ||
38 | + | ||
39 | +var server = app.listen(23023); | ||
40 | + |
1 | +{ | ||
2 | + "name": "experiments11", | ||
3 | + "version": "1.0.0", | ||
4 | + "description": "", | ||
5 | + "main": "app.js", | ||
6 | + "scripts": { | ||
7 | + "test": "echo \"Error: no test specified\" && exit 1" | ||
8 | + }, | ||
9 | + "repository": { | ||
10 | + "type": "git", | ||
11 | + "url": "git@khuhub.khu.ac.kr:Prof.JinSeongwook/OSS-2017-02.git" | ||
12 | + }, | ||
13 | + "author": "", | ||
14 | + "license": "ISC", | ||
15 | + "dependencies": { | ||
16 | + "aws-sdk": "^2.62.0", | ||
17 | + "express-fileupload": "^0.1.3" | ||
18 | + } | ||
19 | +} |
LectureNotes/Chapter12.pdf
0 → 100755
No preview for this file type
LectureNotes/Experiments12.pdf
0 → 100755
No preview for this file type
-
Please register or login to post a comment