package service // func UeditorAction(c *gin.Context) { // action := c.Query("action") // switch action { // //自动读入配置文件,只要初始化UEditor即会发生 // case "config": // callback := c.Query("callback") // jsonByte, _ := ioutil.ReadFile("ueditor-config.json") // re, _ := regexp.Compile("\\/\\*[\\S\\s]+?\\*\\/") // jsonByte = re.ReplaceAll(jsonByte, []byte("")) // c.Writer.Write([]byte(callback + "(" + string(jsonByte) + ")")) // case "uploadimage": // { // var qiniu upload.Qiniu // //保存上传的图片 // //获取上传的文件,直接可以获取表单名称对应的文件名,不用另外提取 // _, fileHeader, err := c.Request.FormFile("upfile") // if err != nil { // data, _ := json.Marshal(map[string]string{ // "state": fmt.Sprintf("获取文件错误: %s", err.Error()), // }) // c.Writer.Write(data) // return // } // fileKey := "ue-img/" + time.Now().Format("20060102") + "/" + fileHeader.Filename // //go func(fileKey string, fileHeader *multipart.FileHeader) { // _, _, err = qiniu.UploadFile2(fileKey, fileHeader) // if err != nil { // data, _ := json.Marshal(map[string]string{ // "state": fmt.Sprintf("上传文件错误: %s", err.Error()), // }) // c.Writer.Write(data) // return // } // //}(fileKey, fileHeader) // data, err := json.Marshal(map[string]string{ // "url": fmt.Sprintf("%s", global.MG_CONFIG.Qiniu.ImgPath+"/"+fileKey), //保存后的文件路径 // "title": "", //文件描述,对图片来说在前端会添加到title属性上 // "original": fileHeader.Filename, //原始文件名 // "state": "SUCCESS", //上传状态,成功时返回SUCCESS,其他任何值将原样返回至图片上传框中 // }) // if err != nil { // panic(err) // } // c.Writer.Write(data) // return // } // case "uploadvideo": // var qiniu upload.Qiniu // _, fileHeader, err := c.Request.FormFile("upfile") // if err != nil { // data, _ := json.Marshal(map[string]string{ // "state": fmt.Sprintf("获取文件错误: %s", err.Error()), // }) // c.Writer.Write(data) // return // } // fileKey := "ue-video/" + time.Now().Format("20060102") + "/" + fileHeader.Filename // //go func(fileKey string, fileHeader *multipart.FileHeader) { // _, _, err = qiniu.UploadFile2(fileKey, fileHeader) // if err != nil { // data, _ := json.Marshal(map[string]string{ // "state": fmt.Sprintf("上传文件错误: %s", err.Error()), // }) // c.Writer.Write(data) // return // } // //}(fileKey, fileHeader) // data, err := json.Marshal(map[string]string{ // "url": fmt.Sprintf("%s", global.MG_CONFIG.Qiniu.ImgPath+"/"+fileKey), //保存后的文件路径 // "title": "", //文件描述,对图片来说在前端会添加到title属性上 // "original": fileHeader.Filename, //原始文件名 // "state": "SUCCESS", //上传状态,成功时返回SUCCESS,其他任何值将原样返回至图片上传框中 // }) // if err != nil { // panic(err) // } // _, err = c.Writer.Write(data) // case "uploadfile": // { // var qiniu upload.Qiniu // //保存上传的文件 // //获取上传的文件,直接可以获取表单名称对应的文件名,不用另外提取 // _, fileHeader, err := c.Request.FormFile("upfile") // if err != nil { // data, _ := json.Marshal(map[string]string{ // "state": fmt.Sprintf("获取文件错误: %s", err.Error()), // }) // c.Writer.Write(data) // return // } // fileKey := "ue-file/" + time.Now().Format("20060102") + "/" + fileHeader.Filename // //go func(fileKey string, fileHeader *multipart.FileHeader) { // _, _, err = qiniu.UploadFile2(fileKey, fileHeader) // if err != nil { // data, _ := json.Marshal(map[string]string{ // "state": fmt.Sprintf("上传文件错误: %s", err.Error()), // }) // c.Writer.Write(data) // return // } // //}(fileKey, fileHeader) // data, err := json.Marshal(map[string]string{ // "url": fmt.Sprintf("%s", global.MG_CONFIG.Qiniu.ImgPath+"/"+fileKey), //保存后的文件路径 // "title": "", //文件描述,对图片来说在前端会添加到title属性上 // "original": fileHeader.Filename, //原始文件名 // "state": "SUCCESS", //上传状态,成功时返回SUCCESS,其他任何值将原样返回至图片上传框中 // }) // c.Writer.Write(data) // return // } // } // }