feat(context): update multiple upload examples.

This commit is contained in:
Eason Lin 2017-07-16 01:24:01 +08:00
parent f38df9dc19
commit 93191b14e0

View File

@ -2,9 +2,7 @@ package main
import (
"fmt"
"io"
"net/http"
"os"
"github.com/gin-gonic/gin"
)
@ -25,24 +23,9 @@ func main() {
files := form.File["files"]
for _, file := range files {
// Source
src, err := file.Open()
if err != nil {
c.String(http.StatusBadRequest, fmt.Sprintf("file open err: %s", err.Error()))
return
if err:=c.SaveUploadedFile(file,file.Filename);err!=nil{
c.String(http.StatusBadRequest, fmt.Sprintf("upload file err: %s", err.Error()))
}
defer src.Close()
// Destination
dst, err := os.Create(file.Filename)
if err != nil {
c.String(http.StatusBadRequest, fmt.Sprintf("Create file err: %s", err.Error()))
return
}
defer dst.Close()
// Copy
io.Copy(dst, src)
}
c.String(http.StatusOK, fmt.Sprintf("Uploaded successfully %d files with fields name=%s and email=%s.", len(files), name, email))