add SaveToFileWithBuffer
This commit is contained in:
parent
06292a0eca
commit
4c523830a7
@ -29,10 +29,9 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/beego/beego/v2/server/web/session"
|
||||
|
||||
"github.com/beego/beego/v2/server/web/context"
|
||||
"github.com/beego/beego/v2/server/web/context/param"
|
||||
"github.com/beego/beego/v2/server/web/session"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -622,6 +621,26 @@ func (c *Controller) SaveToFile(fromFile, toFile string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
type onlyWriter struct {
|
||||
io.Writer
|
||||
}
|
||||
|
||||
func (c *Controller) SaveToFileWithBuffer(fromFile string, toFile string, buf []byte) error {
|
||||
src, _, err := c.Ctx.Request.FormFile(fromFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
dst, err := os.OpenFile(toFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = io.CopyBuffer(onlyWriter{dst}, src, buf)
|
||||
return err
|
||||
}
|
||||
|
||||
// StartSession starts session and load old session data info this controller.
|
||||
func (c *Controller) StartSession() session.Store {
|
||||
if c.CruSession == nil {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user