add SaveToFile & docs
Showing
2 changed files
with
17 additions
and
0 deletions
| ... | @@ -6,10 +6,12 @@ import ( | ... | @@ -6,10 +6,12 @@ import ( |
| 6 | "encoding/xml" | 6 | "encoding/xml" |
| 7 | "github.com/astaxie/beego/session" | 7 | "github.com/astaxie/beego/session" |
| 8 | "html/template" | 8 | "html/template" |
| 9 | "io" | ||
| 9 | "io/ioutil" | 10 | "io/ioutil" |
| 10 | "mime/multipart" | 11 | "mime/multipart" |
| 11 | "net/http" | 12 | "net/http" |
| 12 | "net/url" | 13 | "net/url" |
| 14 | "os" | ||
| 13 | "path" | 15 | "path" |
| 14 | "strconv" | 16 | "strconv" |
| 15 | "strings" | 17 | "strings" |
| ... | @@ -197,6 +199,21 @@ func (c *Controller) GetFile(key string) (multipart.File, *multipart.FileHeader, | ... | @@ -197,6 +199,21 @@ func (c *Controller) GetFile(key string) (multipart.File, *multipart.FileHeader, |
| 197 | return c.Ctx.Request.FormFile(key) | 199 | return c.Ctx.Request.FormFile(key) |
| 198 | } | 200 | } |
| 199 | 201 | ||
| 202 | func (c *Controller) SaveToFile(fromfile, tofile string) error { | ||
| 203 | file, _, err := c.Ctx.Request.FormFile(fromfile) | ||
| 204 | if err != nil { | ||
| 205 | return err | ||
| 206 | } | ||
| 207 | defer file.Close() | ||
| 208 | f, err := os.OpenFile(tofile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) | ||
| 209 | if err != nil { | ||
| 210 | return err | ||
| 211 | } | ||
| 212 | defer f.Close() | ||
| 213 | io.Copy(f, file) | ||
| 214 | return nil | ||
| 215 | } | ||
| 216 | |||
| 200 | func (c *Controller) StartSession() (sess session.SessionStore) { | 217 | func (c *Controller) StartSession() (sess session.SessionStore) { |
| 201 | sess = GlobalSessions.SessionStart(c.Ctx.ResponseWriter, c.Ctx.Request) | 218 | sess = GlobalSessions.SessionStart(c.Ctx.ResponseWriter, c.Ctx.Request) |
| 202 | return | 219 | return | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment