Skip to content

Commit

Permalink
start recipes, working #32
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Apr 11, 2016
1 parent 7c74425 commit e9fb1ba
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
35 changes: 35 additions & 0 deletions recipes/multipart/README.md
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
```
22 changes: 22 additions & 0 deletions recipes/multipart/index.js
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.

0 comments on commit e9fb1ba

Please sign in to comment.