Skip to content

Commit

Permalink
finish post with data (koa-multer usages)
Browse files Browse the repository at this point in the history
  • Loading branch information
i5ting committed Dec 15, 2015
1 parent 15f0853 commit 8e469e7
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
**/*node_modules
**/*uploads
7 changes: 7 additions & 0 deletions form-data/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ var app = require('koa')()
var index = require('./routes/index');
var users = require('./routes/users');

var multer = require('koa-multer');
var upload = multer({ dest: 'uploads/' })


app.use(multer({ dest: './uploads/'}))


// global middlewares
app.use(views('views', {
root: __dirname + '/views',
Expand Down
Binary file added form-data/img/post-common.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added form-data/img/post-formdata.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added form-data/img/post-rawdata.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions form-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
"start": "node ./bin/www",
"test":"curl -F 'pic=@\"img/post-common.png\"' -F 'a=1' -F 'b=2' http://127.0.0.1:3000/users/post/formdata"
},
"dependencies": {
"co": "^4.6.0",
Expand All @@ -13,9 +14,10 @@
"koa-bodyparser": "^2.0.1",
"koa-json": "^1.1.1",
"koa-logger": "^1.3.0",
"koa-multer": "0.0.2",
"koa-onerror": "^1.2.1",
"koa-router": "^5.3.0",
"koa-static": "^1.5.2",
"koa-views": "^3.1.0"
}
}
}
7 changes: 7 additions & 0 deletions form-data/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@ router.get('/', function *(next) {
this.body = 'this a users response!';
});

router.post('/post/formdata', function *(next) {
console.dir(this.req.body)
console.dir(this.req.files)

this.body = 'this a users response!';
});

module.exports = router;
5 changes: 3 additions & 2 deletions form-urlencoded/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"start": "node ./bin/www",
"test":"curl -d 'a=1&b=2' http://127.0.0.1:3000/users/post"
"test": "curl -d 'a=1&b=2' http://127.0.0.1:3000/users/post"
},
"dependencies": {
"co": "^4.6.0",
Expand All @@ -14,9 +14,10 @@
"koa-bodyparser": "^2.0.1",
"koa-json": "^1.1.1",
"koa-logger": "^1.3.0",
"koa-multer": "0.0.2",
"koa-onerror": "^1.2.1",
"koa-router": "^5.3.0",
"koa-static": "^1.5.2",
"koa-views": "^3.1.0"
}
}
}

0 comments on commit 8e469e7

Please sign in to comment.