From 55334da20cff4dac840c320eda1d0ca53ba27eda Mon Sep 17 00:00:00 2001 From: fwq <582742538@qq.com> Date: 星期一, 23 九月 2024 14:26:36 +0800 Subject: [PATCH] Merge branch 'master-stander' into master-xlk --- src/main/java/com/hx/util/OBSUtil.java | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/hx/util/OBSUtil.java b/src/main/java/com/hx/util/OBSUtil.java index 56be8ed..87b0ea8 100644 --- a/src/main/java/com/hx/util/OBSUtil.java +++ b/src/main/java/com/hx/util/OBSUtil.java @@ -32,7 +32,7 @@ * @return * @throws IOException */ - public static PutObjectResult uploadImg(MultipartFile localFile,String ak,String sk,String endPoint,String bucketName,String fileName) throws IOException { + public static PutObjectResult uploadImg(MultipartFile localFile,String ak,String sk,String endPoint,String bucketName,String folderName,String fileName) throws IOException { //娌℃湁鍚嶆鐨勬椂鍊欒嚜鍔ㄧ敓鎴� if(StringUtils.isNull(fileName)){ @@ -41,13 +41,16 @@ fileName += localFile.getOriginalFilename().substring(localFile.getOriginalFilename().lastIndexOf(".")); } } + if(StringUtils.noNull(folderName)){ + fileName = folderName+"/"+fileName; + } PutObjectResult putObjectResult = null; //鍒濆鍖朞BS瀹㈡埛绔� ObsClient obsClient = new ObsClient(ak, sk, endPoint); try{ - putObjectResult = obsClient.putObject(bucketName, fileName, localFile.getInputStream()); + putObjectResult = obsClient.putObject(bucketName,fileName , localFile.getInputStream()); }catch (ObsException e){ logger.error("鍗庝负浜� OBS 涓婁紶鏂囦欢鎶ラ敊 "); logger.error("HTTP Code: " + e.getResponseCode()); @@ -73,11 +76,12 @@ * @param sk 璁块棶绉橀挜 * @param endPoint 鍖哄煙 * @param bucketName 瀛樺偍妗� + * @param folderName 鏂囦欢澶瑰悕绉� * @param fileName 鏂囦欢鍚嶇О锛堝甫鍚庣紑锛夛紝涓虹┖鏃惰嚜鍔ㄧ敓鎴� * @return * @throws IOException */ - public static PutObjectResult uploadImg(File localFile,String ak,String sk,String endPoint,String bucketName,String fileName) throws IOException { + public static PutObjectResult uploadImg(File localFile,String ak,String sk,String endPoint,String bucketName,String folderName,String fileName) throws IOException { //娌℃湁鍚嶆鐨勬椂鍊欒嚜鍔ㄧ敓鎴� if(StringUtils.isNull(fileName)){ @@ -86,6 +90,9 @@ fileName += localFile.getName().substring(localFile.getName().lastIndexOf(".")); } } + if(StringUtils.noNull(folderName)){ + fileName = folderName+"/"+fileName; + } PutObjectResult putObjectResult = null; -- Gitblit v1.8.0