It doesn't appear as if Beego has a convenient method for uploading multiple files. GetFile() just wraps FromFile() from the standard library. You probably want to use the standard library's reader function: r.MultipartReader().
In situations like this, I usually expose the response reader and writer from the controller by calling:
w = this.Ctx.ResponseWriter
r = this.Ctx.ResponseReader
Now I'm able to use the net/http package in the standard way and implement solutions external to the framework.
A quick search for uploading multiple files in Go leads me to helpful blog post.
In the interest of protecting this answer from link rot, here is the author's solution:
func uploadHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
//GET displays the upload form.
case "GET":
display(w, "upload", nil)
//POST takes the uploaded file(s) and saves it to disk.
case "POST":
//get the multipart reader for the request.
reader, err := r.MultipartReader()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
//copy each part to destination.
for {
part, err := reader.NextPart()
if err == io.EOF {
break
}
//if part.FileName() is empty, skip this iteration.
if part.FileName() == "" {
continue
}
dst, err := os.Create("/home/sanat/" + part.FileName())
defer dst.Close()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if _, err := io.Copy(dst, part); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
//display success message.
display(w, "upload", "Upload successful.")
default:
w.WriteHeader(http.StatusMethodNotAllowed)
}
}