From fe729234647c83f8029beba4e31dc8d364a6427b Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期三, 27 八月 2025 16:04:35 +0800
Subject: [PATCH] 修BUG
---
server/services/src/main/java/com/doumee/api/common/PublicCloudController.java | 75 +++++++++++++++++++++++++++++++++----
1 files changed, 67 insertions(+), 8 deletions(-)
diff --git a/server/services/src/main/java/com/doumee/api/common/PublicCloudController.java b/server/services/src/main/java/com/doumee/api/common/PublicCloudController.java
index 6a8ff19..f4addb1 100644
--- a/server/services/src/main/java/com/doumee/api/common/PublicCloudController.java
+++ b/server/services/src/main/java/com/doumee/api/common/PublicCloudController.java
@@ -14,6 +14,7 @@
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.FtpUtil;
import com.doumee.core.utils.azure.AzureBlobUtil;
+import com.doumee.core.utils.huaweiOBS.ObsUtil;
import com.doumee.core.utils.qiyeweixin.QywxUtil;
import com.doumee.core.utils.qiyeweixin.model.response.QywxUploadMediaResponse;
import com.doumee.dao.system.model.SystemDictData;
@@ -53,20 +54,78 @@
@Autowired
private SystemDictDataBiz systemDictDataBiz;
- @ApiOperation(value = "涓婁紶", notes = "涓婁紶", httpMethod = "POST", position = 6)
+ @ApiOperation(value = "涓婁紶OBS", notes = "涓婁紶OBS", httpMethod = "POST", position = 6)
@ApiImplicitParams({
@ApiImplicitParam(name = "folder", value = "鏂囦欢澶�", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
@ApiImplicitParam(name = "file", value = "鏂囦欢澶�", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
})
- @PostMapping(value = "/uploadLocal", headers = "content-type=multipart/form-data")
- public void uploadLocal(HttpServletRequest request, HttpServletResponse response) throws Exception {
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- uploadFileLocal(multipartRequest, response,
- systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.IMG_DIR).getCode() ,
- systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode());
-
+ @PostMapping(value = "/upload", headers = "content-type=multipart/form-data")
+ @ResponseBody
+ public void upload(HttpServletRequest request, HttpServletResponse response, String folder,String flag) throws Exception {
+ Date d1 = new Date();
+ log.error("鎬诲緱涓婁紶鏂囦欢鎴愬姛=============寮�濮�========="+DateUtil.getPlusTime2(d1));
+ if(Objects.isNull(folder)){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐩爣鏂囦欢澶归敊璇�");
+ }
+ String prefixPath = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.RESOURCE_PATH).getCode();
+ InputStream is = null;
+ response.setCharacterEncoding("UTF-8");
+ response.setContentType("text/html;charset=UTF-8");
+ Map<String, Object> context = new HashMap<>();
+ try {
+ CommonsMultipartResolver multipartResovler = new CommonsMultipartResolver();
+ if (multipartResovler.isMultipart(request)) {
+ MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+ Iterator<String> it = multipartRequest.getFileNames();
+ while (it.hasNext()) {
+ MultipartFile file = multipartRequest.getFile(it.next());
+ System.out.println(file.getSize());
+ String originname = file.getOriginalFilename();
+ is = file.getInputStream();
+ String endType = ".jpg";
+ if(originname.indexOf(".")>0){
+ endType=originname.substring(originname.lastIndexOf("."),originname.length());
+ }
+ String date = DateUtil.getNowShortDate();
+ String fName = date+"/"+ UUID.randomUUID()+endType;
+ String fileName = folder+"/"+fName;
+ boolean r =false;
+ ObsUtil obsUtil = new ObsUtil( systemDictDataBiz.queryByCode(Constants.HWY_OBS,Constants.HWY_OBS_ACCESSID).getCode(),
+ systemDictDataBiz.queryByCode(Constants.HWY_OBS,Constants.HWY_OBS_ACCESSKEY).getCode(),
+ systemDictDataBiz.queryByCode(Constants.HWY_OBS,Constants.HWY_OBS_ENDPOINT).getCode());
+ r = obsUtil.uploadFile( systemDictDataBiz.queryByCode(Constants.HWY_OBS,Constants.HWY_OBS_BUCKET).getCode(),is,fileName);//涓婁紶
+ if(r){
+ context.put("success", true);
+ context.put("code", 200);
+ context.put("errno",0);
+ JSONObject fileJSON = new JSONObject();
+// fileJSON.put("prefixPath", prefixPath);
+// fileJSON.put("folder", folder);
+ fileJSON.put("url", prefixPath+fileName);
+ fileJSON.put("imgaddr", fName);
+ fileJSON.put("imgname", fileName);
+ fileJSON.put("originname", originname);
+ fileJSON.put("flag", flag);
+ context.put("data",fileJSON);
+ context.put("message","璇锋眰鎴愬姛");
+ writerJson(response, context);
+ Date d2= new Date();
+ log.error("鎬荤殑涓婁紶鏂囦欢鎴愬姛=============缁撴潫========="+DateUtil.getPlusTime2(d2) +"鑰楁椂绉掞細"+( (d2.getTime()-d1.getTime()) /1000));
+ return;
+ }
+ }
+ }
+ } catch (Exception e) {
+ log.error("銆愪笂浼燜TP澶辫触銆�======================"+e.getMessage());
+ }
+ context.put("code", 0);
+ context.put("message", "涓婁紶澶辫触");
+ context.put("errno",0);
+ writerJson(response, context);
+ return;
}
+
public void uploadFileLocal(HttpServletRequest request, HttpServletResponse response, String rootPath,String dir) throws Exception {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
--
Gitblit v1.9.3