From db287aac9eb5032b1158b405a9b4807301467ed3 Mon Sep 17 00:00:00 2001 From: zhouxiang <zhouxiang> Date: 星期四, 24 三月 2022 17:48:03 +0800 Subject: [PATCH] 添加redis获取整个hashKey数据和单个hashKey数据方法 --- src/main/java/com/hx/util/OBSUtil.java | 15 +++++++++++---- 1 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/hx/util/OBSUtil.java b/src/main/java/com/hx/util/OBSUtil.java index fc74c7b..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,13 +90,16 @@ fileName += localFile.getName().substring(localFile.getName().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); + putObjectResult = obsClient.putObject(bucketName, fileName, localFile); }catch (ObsException e){ logger.error("鍗庝负浜� OBS 涓婁紶鏂囦欢鎶ラ敊 "); logger.error("HTTP Code: " + e.getResponseCode()); -- Gitblit v1.8.0