background/controller/file.go

43 lines
831 B
Go

package controller
import (
"fmt"
"github.com/gin-gonic/gin"
"io"
"log"
"os"
)
type FileController struct {
}
func (this *FileController) OnUpload(c *gin.Context) {
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)
}
}
func (this *FileController) OnDownLoad(c *gin.Context) {
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)
}
}