c143a6ec by astaxie

fix #1090 add Getfiles to support mulit file upload

1 parent e619d839
...@@ -499,6 +499,41 @@ func (c *Controller) GetFile(key string) (multipart.File, *multipart.FileHeader, ...@@ -499,6 +499,41 @@ func (c *Controller) GetFile(key string) (multipart.File, *multipart.FileHeader,
499 return c.Ctx.Request.FormFile(key) 499 return c.Ctx.Request.FormFile(key)
500 } 500 }
501 501
502 // GetFiles return multi-upload files
503 // files, err:=c.Getfiles("myfiles")
504 // if err != nil {
505 // http.Error(w, err.Error(), http.StatusNoContent)
506 // return
507 // }
508 // for i, _ := range files {
509 // //for each fileheader, get a handle to the actual file
510 // file, err := files[i].Open()
511 // defer file.Close()
512 // if err != nil {
513 // http.Error(w, err.Error(), http.StatusInternalServerError)
514 // return
515 // }
516 // //create destination file making sure the path is writeable.
517 // dst, err := os.Create("upload/" + files[i].Filename)
518 // defer dst.Close()
519 // if err != nil {
520 // http.Error(w, err.Error(), http.StatusInternalServerError)
521 // return
522 // }
523 // //copy the uploaded file to the destination file
524 // if _, err := io.Copy(dst, file); err != nil {
525 // http.Error(w, err.Error(), http.StatusInternalServerError)
526 // return
527 // }
528 // }
529 func (c *Controller) GetFiles(key string) ([]*multipart.FileHeader, error) {
530 files, ok := c.Ctx.Request.MultipartForm.File["key"]
531 if ok {
532 return files, nil
533 }
534 return nil, http.ErrMissingFile
535 }
536
502 // SaveToFile saves uploaded file to new path. 537 // SaveToFile saves uploaded file to new path.
503 // it only operates the first one of mutil-upload form file field. 538 // it only operates the first one of mutil-upload form file field.
504 func (c *Controller) SaveToFile(fromfile, tofile string) error { 539 func (c *Controller) SaveToFile(fromfile, tofile string) error {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!