| | |
| | | * @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)){ |
| | |
| | | fileName += localFile.getOriginalFilename().substring(localFile.getOriginalFilename().lastIndexOf(".")); |
| | | } |
| | | } |
| | | if(StringUtils.noNull(folderName)){ |
| | | fileName = folderName+"/"+fileName; |
| | | } |
| | | |
| | | PutObjectResult putObjectResult = null; |
| | | |
| | | //初始化OBS客户端 |
| | | 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()); |
| | |
| | | * @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)){ |
| | |
| | | fileName += localFile.getName().substring(localFile.getName().lastIndexOf(".")); |
| | | } |
| | | } |
| | | if(StringUtils.noNull(folderName)){ |
| | | fileName = folderName+"/"+fileName; |
| | | } |
| | | |
| | | PutObjectResult putObjectResult = null; |
| | | |
| | | //初始化OBS客户端 |
| | | 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()); |