package fileuploaddownload import ( "os" "path" "strconv" "time" "github.com/flipped-aurora/gin-vue-admin/server/commonus" "github.com/flipped-aurora/gin-vue-admin/server/model/common/response" "github.com/gin-gonic/gin" ) type FileUploadDownload struct{} type urlData struct { Type int `json:"type"` Sign string `json:"sign"` } //上传文件(远程) func (f *FileUploadDownload) LongRangeFileUpload(c *gin.Context) { _, fileHeader, fileErr := c.Request.FormFile("file") typePostForm := c.PostForm("type") var urlData urlData if urlData.Type == 0 { typePostFormInt, _ := strconv.Atoi(typePostForm) urlData.Type = typePostFormInt } if fileErr != nil { response.Result(101, fileHeader, "获取文件错误!", c) return } // fileNameAry := strings.Split(fileHeader.Filename, ".") //拆分文件名称,获取类型及文件原名 // if len(fileNameAry) < 2 { // response.Result(0, fileHeader, "文件上传错误!", c) // return // } localFileSave := "uploads/" + fileHeader.Filename c.SaveUploadedFile(fileHeader, localFileSave) // filePath := "G:/goobject/src/git_public/gin-vue-admin/gin_server_admin/go.mod" // strinUrl := "http://docu.hxgk.net/uploadfileing/uploadimging" str, _ := os.Getwd() filePath := str + "/" + localFileSave //文件转接物理地址 outPut := commonus.MapOut() // outPut["fileAttr"] = fileAttr fileCallBack := postFormDataWithSingleFile(filePath, urlData.Type) // outPut["msg"] = urlData if fileCallBack.Code != 0 && fileCallBack.Code != 1 { response.Result(102, outPut, fileCallBack.Msg, c) return } // var fileAttr FileAttribute //获取文件基础属性 var upLoadFileStruct UpLoadFileStruct upLoadFileStruct.ID = commonus.GetFileNumberEs() upLoadFileStruct.CreatedAt = time.Now() upLoadFileStruct.UpdatedAt = time.Now() upLoadFileStruct.Key = fileCallBack.Data.NewName upLoadFileStruct.Name = fileHeader.Filename upLoadFileStruct.Tag = path.Ext(fileHeader.Filename) upLoadFileStruct.Url = fileCallBack.Data.Callbackurl upLoadFileStruct.PhysicsPath = fileCallBack.Data.Physicspath upLoadFileStruct.FileSize = fileCallBack.Data.GetSize // outPut["CallBackFileIng"] = postFormDataWithSingleFile(filePath, urlData.Type) os.RemoveAll(filePath) //删除转接文件 outPut["file"] = upLoadFileStruct // fmt.Printf("返回值====》%v\n", outPut) response.Result(0, upLoadFileStruct, fileCallBack.Msg, c) }