Skip to content

Commit 09531dc

Browse files
committed
上传成功
1 parent e3b5a6f commit 09531dc

25 files changed

+19960
-3
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ jspm_packages
3636

3737
# Optional REPL history
3838
.node_repl_history
39+
40+
41+
.DS_Store

app.js

+36-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,49 @@
11
var config = require('./config')
22
var express = require('express')
3+
var bodyParser = require('body-parser')
4+
var multer = require('multer');
5+
var request = require('request')
6+
37
var authMiddleware = require('./middleware/auth')
48

59

610
var app = express();
11+
app.set('views', './view')
12+
app.set('view engine', 'ejs');
13+
14+
app.use(bodyParser.urlencoded({extended: true}))
715

16+
app.use('/static', express.static('./static'))
817
app.use(authMiddleware.userAuth)
918

1019
app.get('/', function (req, res) {
11-
res.send('hello world')
20+
res.render('index')
21+
})
22+
23+
app.post('/upload', multer().single('pic_file'), function (req, res) {
24+
var uploadUrl = config.api_backend + '/upload'
25+
26+
var picFile = req.file;
27+
28+
request.post({
29+
url: uploadUrl,
30+
formData: {
31+
image: {
32+
value: picFile.buffer,
33+
options: {
34+
filename: picFile.originalname,
35+
contentType: picFile.mimetype
36+
}
37+
}
38+
}
39+
}, function (err, response) {
40+
if (err) {
41+
return res.send(err)
42+
}
43+
res.redirect('/')
44+
})
45+
46+
1247
})
1348

1449
app.listen(config.web_app_port, function () {

config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ var config = {
44
account: {
55
alsotang: 'hehefuhehe',
66
linktang: 'muerqiaohuiche',
7-
}
7+
},
8+
api_backend: 'http://119.29.70.101:3000',
89
}
910

1011

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
"dependencies": {
2020
"express": "^4.14.0",
2121
"eventproxy": "^0.3.4",
22-
"basic-auth": "^1.0.4"
22+
"basic-auth": "^1.0.4",
23+
"ejs": "^2.4.2",
24+
"body-parser": "^1.15.2",
25+
"multer": "^1.1.0",
26+
"request": "^2.73.0"
2327
}
2428
}

static/css/custom.css

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
padding-top: 70px;
3+
padding-bottom: 30px;
4+
}

0 commit comments

Comments
 (0)