Skip to content

Commit

Permalink
fix #55 add SaveToFile
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon committed Sep 17, 2015
1 parent 635c89a commit 05317cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Macaron [![Build Status](https://drone.io/github.com/Unknwon/macaron/status.png)

Package macaron is a high productive and modular design web framework in Go.

##### Current version: 0.6.6
##### Current version: 0.6.7

## Getting Started

Expand Down
18 changes: 18 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,24 @@ func (ctx *Context) GetFile(name string) (multipart.File, *multipart.FileHeader,
return ctx.Req.FormFile(name)
}

// SaveToFile reads a file from request by field name and saves to given path.
func (ctx *Context) SaveToFile(name, savePath string) error {
fr, _, err := ctx.GetFile(name)
if err != nil {
return err
}
defer fr.Close()

fw, err := os.OpenFile(savePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
return err
}
defer fw.Close()

_, err = io.Copy(fw, fr)
return err
}

// SetCookie sets given cookie value to response header.
// FIXME: IE support? http://golanghome.com/post/620#reply2
func (ctx *Context) SetCookie(name string, value string, others ...interface{}) {
Expand Down
2 changes: 1 addition & 1 deletion macaron.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/Unknwon/macaron/inject"
)

const _VERSION = "0.6.6.0728"
const _VERSION = "0.6.7.0916"

func Version() string {
return _VERSION
Expand Down

0 comments on commit 05317cf

Please sign in to comment.