background/controller/file.go

44 lines
833 B
Go
Raw Normal View History

2019-03-07 06:06:29 +00:00
package controller
2019-01-29 13:57:53 +00:00
import (
"fmt"
"github.com/gin-gonic/gin"
"io"
"log"
"os"
)
2019-03-07 06:06:29 +00:00
type FileController struct {
}
func (this *FileController) OnUpload(c *gin.Context) {
2019-01-29 13:57:53 +00:00
file, header, err := c.Request.FormFile("upload")
filename := header.Filename
fmt.Println(header.Filename)
out, err := os.Create("G://GoPath//image//" + filename + ".png")
if err != nil {
log.Fatal(err)
}
defer out.Close()
_, err = io.Copy(out, file)
if err != nil {
log.Fatal(err)
}
}
2019-03-07 06:06:29 +00:00
func (this *FileController) OnDownLoad(c *gin.Context) {
2019-01-29 13:57:53 +00:00
file, header, err := c.Request.FormFile("upload")
filename := header.Filename
fmt.Println(header.Filename)
out, err := os.Create("G://GoPath//image//" + filename + ".png")
if err != nil {
log.Fatal(err)
}
defer out.Close()
_, err = io.Copy(out, file)
if err != nil {
log.Fatal(err)
}
}