From d57fc1094625792b20d5ec713bcf9dfb1901ed68 Mon Sep 17 00:00:00 2001 From: fwq <582742538@qq.com> Date: 星期五, 01 九月 2023 10:17:15 +0800 Subject: [PATCH] 增加Excel解析不为空的校验 --- 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