forked from mirror/gin
add error check. (#972)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
df67c64479
commit
baf216e167
|
@ -17,16 +17,28 @@ func main() {
|
|||
email := c.PostForm("email")
|
||||
|
||||
// Multipart form
|
||||
form, _ := c.MultipartForm()
|
||||
form, err := c.MultipartForm()
|
||||
if err != nil {
|
||||
c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
|
||||
return
|
||||
}
|
||||
files := form.File["files"]
|
||||
|
||||
for _, file := range files {
|
||||
// Source
|
||||
src, _ := file.Open()
|
||||
src, err := file.Open()
|
||||
if err != nil {
|
||||
c.String(http.StatusBadRequest, fmt.Sprintf("file open err: %s", err.Error()))
|
||||
return
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
// Destination
|
||||
dst, _ := os.Create(file.Filename)
|
||||
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
|
||||
|
|
|
@ -17,12 +17,24 @@ func main() {
|
|||
email := c.PostForm("email")
|
||||
|
||||
// Source
|
||||
file, _ := c.FormFile("file")
|
||||
src, _ := file.Open()
|
||||
file, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
|
||||
return
|
||||
}
|
||||
src, err := file.Open()
|
||||
if err != nil {
|
||||
c.String(http.StatusBadRequest, fmt.Sprintf("file open err: %s", err.Error()))
|
||||
return
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
// Destination
|
||||
dst, _ := os.Create(file.Filename)
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue