| | |
| | | package com.stylefeng.guns.modular.system.controller.system; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.stylefeng.guns.modular.system.util.OssUploadUtil ; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.heredata.hos.model.bucket.Bucket; |
| | | import com.stylefeng.guns.config.properties.GunsProperties; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.system.util.qianyuntong.NCOSSUtil; |
| | | import com.stylefeng.guns.modular.system.util.qianyuntong.QianYunTongProperties; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.web.multipart.MultipartHttpServletRequest; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.UUID; |
| | | |
| | | @Controller |
| | | public class UediterController { |
| | | /*@RequestMapping("/config") |
| | | public String getConfigInfo(HttpServletRequest request,HttpServletResponse response){ |
| | | return "redirect:/static/js/ueditor/jsp/jsp/config.json"; |
| | | }*/ |
| | | |
| | | /*@RequestMapping("/config") |
| | | public String getConfigInfo(HttpServletRequest request,HttpServletResponse response){ |
| | | return "redirect:/static/js/ueditor/jsp/jsp/config.json"; |
| | | }*/ |
| | | public final static String UEDITOR_CONFIG = "{\n" + |
| | | " \"imageActionName\": \"uploadimage\",\n" + |
| | | " \"imageFieldName\": \"upfile\",\n" + |
| | |
| | | " ] \n" + |
| | | "\n" + |
| | | "}"; |
| | | @Autowired |
| | | private GunsProperties gunsProperties; |
| | | |
| | | @RequestMapping(value = "/config") |
| | | @ResponseBody |
| | | public JSON config(String action, HttpServletRequest request, HttpServletResponse response) { |
| | |
| | | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
| | | MultipartFile picture = multipartRequest.getFile("upfile"); |
| | | String callback = request.getParameter("callback"); |
| | | String pictureName = ""; |
| | | try { |
| | | //文件上传,具体根据实际替换 |
| | | pictureName = OssUploadUtil.ossUpload(request, picture); |
| | | |
| | | String pictureName = UUID.randomUUID().toString() + "." + ToolUtil.getFileSuffix(picture.getOriginalFilename()); |
| | | String bucketName = QianYunTongProperties.bucketName; |
| | | Bucket grjyTest = NCOSSUtil.getBucketInfo(bucketName); |
| | | if (null == grjyTest) { |
| | | //创建桶 |
| | | Boolean bucket = NCOSSUtil.createBucket(bucketName); |
| | | if (!bucket) { |
| | | throw new RuntimeException("创建存储桶失败"); |
| | | } |
| | | //设置桶策略 |
| | | String policyText = "{\"Version\":\"2025-06-23\",\"Statement\":[{\"Sid\":\"Stmt20250623\",\"Action\":[\"GetObject\"],\"Effect\":\"Allow\",\"Resource\":\"" + bucketName + "/*\",\"Principal\":\"*\"}]}"; |
| | | Boolean bucketPolicy = NCOSSUtil.setBucketPolicy(bucketName, policyText); |
| | | if (!bucketPolicy) { |
| | | throw new RuntimeException("设置桶策略失败"); |
| | | } |
| | | } |
| | | //上传对象 |
| | | String key = "imgs/management/" + pictureName; |
| | | String object = NCOSSUtil.putObject(bucketName, key, picture.getInputStream()); |
| | | if (null == object) { |
| | | throw new RuntimeException("上传图片失败"); |
| | | } |
| | | |
| | | pictureName = "https://traffic.qytzt.cn/v1/AUTH_" + QianYunTongProperties.account + "/" + bucketName + "/" + key; |
| | | |
| | | |
| | | //文件上传,具体根据实际替换 |
| | | // pictureName = OssUploadUtil.ossUpload(request, picture); |
| | | |
| | | String result = "{'original': '" + picture.getOriginalFilename() + "', 'state': 'SUCCESS', 'url': '" + pictureName + "'}"; |
| | | if (callback == null) { |
| | | return JSON.parseObject(result); |