点击(此处)折叠或打开
  func thUploadFile(w http.ResponseWriter, r *http.Request) {


  1. .....
  2. //解决跨域问题
  3. if origin := r.Header.Get("Origin"); origin != "" {
  4.             w.Header().Set("Access-Control-Allow-Origin", "*")
  5.             w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")

  6.         }
  7.         r.ParseMultipartForm(32 << 20)
  8. //解决上传多个文件问题,每个文件分别保存
  9.         fhs := r.MultipartForm.File["uploadfile"]
  10.         for _, fh := range fhs {

  11.             file, _ := fh.Open()
  12.             f, err := os.OpenFile(thUpload_Dir+fh.Filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
  13.             if err != nil {
  14.                 slog.Error("打开文件错误")
  15.                 return
  16.             }
  17.             defer f.Close()
  18.             io.Copy(f, file)

  19.             //filedir, _ := filepath.Abs(Upload_Dir + fh.Filename)
  20.             //fmt.Fprintf(w, "%v", fh.Filename+"上传完成,服务器地址:"+filedir)
  21.         }
  22. ....

10-01 21:41