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")
|
email := c.PostForm("email")
|
||||||
|
|
||||||
// Multipart form
|
// 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"]
|
files := form.File["files"]
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
// Source
|
// 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()
|
defer src.Close()
|
||||||
|
|
||||||
// Destination
|
// 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()
|
defer dst.Close()
|
||||||
|
|
||||||
// Copy
|
// Copy
|
||||||
|
|
|
@ -17,12 +17,24 @@ func main() {
|
||||||
email := c.PostForm("email")
|
email := c.PostForm("email")
|
||||||
|
|
||||||
// Source
|
// Source
|
||||||
file, _ := c.FormFile("file")
|
file, err := c.FormFile("file")
|
||||||
src, _ := file.Open()
|
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()
|
defer src.Close()
|
||||||
|
|
||||||
// Destination
|
// 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()
|
defer dst.Close()
|
||||||
|
|
||||||
// Copy
|
// Copy
|
||||||
|
|
Loading…
Reference in New Issue