点击(此处)折叠或打开
func thUploadFile(w http.ResponseWriter, r *http.Request) {
- .....
- //解决跨域问题
- if origin := r.Header.Get("Origin"); origin != "" {
- w.Header().Set("Access-Control-Allow-Origin", "*")
- w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
- }
- r.ParseMultipartForm(32 << 20)
- //解决上传多个文件问题,每个文件分别保存
- fhs := r.MultipartForm.File["uploadfile"]
- for _, fh := range fhs {
- file, _ := fh.Open()
- f, err := os.OpenFile(thUpload_Dir+fh.Filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
- if err != nil {
- slog.Error("打开文件错误")
- return
- }
- defer f.Close()
- io.Copy(f, file)
- //filedir, _ := filepath.Abs(Upload_Dir + fh.Filename)
- //fmt.Fprintf(w, "%v", fh.Filename+"上传完成,服务器地址:"+filedir)
- }
- ....