func SaveUploadedFile(file *multipart.FileHeader, dst string) error{
src, err := file.Open()
if err != nil {
return err
}
defer src.Close()

out, err := os.Create(dst)
if err != nil {
return err
}
defer out.Close()

_, err = io.Copy(out, src)
return err
}

func UPLoad(w http.ResponseWriter,req *http.Request) {
file,files,err := req.FormFile("upload")
logger.Trace(types.ModuleAmfAgent,logger.INFO,nil,file)
if err != nil{
logger.Trace(types.ModuleAmfAgent,logger.INFO,nil,err)
fmt.Println(err)
}
dst := path.Join("./config/",files.Filename)
err1 := SaveUploadedFile(files,dst)
if err1 != nil{
logger.Trace(types.ModuleAmfAgent,logger.ERROR,nil,err1)
}
resp := webTypes.ParamsSettingRespData{200, "success", nil}
agent.RespData(w, resp)

}

posted on 2021-07-06 15:07  小强de博客  阅读(353)  评论(0编辑  收藏  举报