app.js
893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const express = require('express');
const fileUpload = require('express-fileupload');
const app = express();
//var aws = require('aws-sdk');
//aws.config.loadFromPath('./awsconfig.json');
//var BUCKET_NAME = 'intothegalaxy';
//var s3 = new aws.S3();
function uploadFile(file, res) {
// Use the mv() method to place the file somewhere on your server
file.mv('./upload/' + file.name, function(err) {
if (err)
return res.status(500).send(err);
res.send('File uploaded!');
});
}
// default options
app.use(fileUpload());
app.post('/', function(req, res) {
if (!req.files)
return res.status(400).send('No files were uploaded.');
uploadFile(req.files.file, res);
});
app.get('/:fileName', function(req, res){
var file = __dirname + '/upload/' + req.params.fileName;
res.download(file); // Set disposition and send it.
});
var server = app.listen(23023);