-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tunnckoCore
committed
Apr 11, 2016
1 parent
7c74425
commit e9fb1ba
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
## multipart | ||
|
||
text text text... | ||
|
||
```js | ||
'use strict' | ||
|
||
var app = require('koa')() | ||
var path = require('path') | ||
var body = require('koa-better-body') | ||
|
||
app | ||
.use(body({ | ||
encoding: 'utf-8', | ||
uploadDir: path.join(__dirname, 'uploads'), | ||
keepExtensions: true | ||
})) | ||
.use(function * () { | ||
console.log(this.request.files) // or `this.body.files` | ||
console.log(this.body.files.foo.name) // => README.md | ||
console.log(this.body.files.foo.path) // => full filepath to where is uploaded | ||
}) | ||
|
||
app.listen(4290, function () { | ||
console.log('Koa server start listening on port 4290') | ||
console.log('curl -i http://localhost:4290/ -F "foo=@%s/README.md"', __dirname) | ||
}) | ||
``` | ||
|
||
## Try it | ||
> You can try above example by running: | ||
``` | ||
node recipes/multipart | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
var app = require('koa')() | ||
var path = require('path') | ||
var body = require('../../index') | ||
|
||
app | ||
.use(body({ | ||
encoding: 'utf-8', | ||
uploadDir: path.join(__dirname, 'uploads'), | ||
keepExtensions: true | ||
})) | ||
.use(function * () { | ||
console.log(this.request.files) // or `this.body.files` | ||
console.log(this.body.files.foo.name) // => README.md | ||
console.log(this.body.files.foo.path) // => full filepath to where is uploaded | ||
}) | ||
|
||
app.listen(4290, function () { | ||
console.log('Koa server start listening on port 4290') | ||
console.log('curl -i http://localhost:4290/ -F "foo=@%s/README.md"', __dirname) | ||
}) |
Empty file.