beego bulk upload

Beego recently used in the project, the need to achieve bulk upload file, turned for a long time beego documents are not satisfactory solution is found, and found that the author has given the relevant implementation code, 560 in the source package in time to see the source code file controller.go -586 line, recorded as follows:

//GetFiles return multi-upload files
files, err:=c.GetFiles("myfiles")
    if err != nil {
        http.Error(w, err.Error(), http.StatusNoContent)
        return
    }
for i, _ := range files {
    //for each fileheader, get a handle to the actual file
    file, err := files[i].Open()
    defer file.Close()
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }
    //create destination file making sure the path is writeable.
    dst, err := os.Create("upload/" + files[i].Filename)
    defer dst.Close()
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }
    //copy the uploaded file to the destination file
    if _, err := io.Copy(dst, file); err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }
}

Tag to be set corresponding to the input multipleattributes

<input type="file" multiple name="myfiles">

Guess you like

Origin www.cnblogs.com/prince5460/p/12000046.html