1、引入依赖(gradle)

    // asw s3 亚马逊云存储implementation 'com.amazonaws:aws-java-sdk-s3:1.11.830'// minio clientapi "io.minio:minio:8.2.1"// oss clientimplementation 'com.aliyun.oss:aliyun-sdk-oss:3.10.2'

2、MINIO

import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.RemoveBucketArgs;
import io.minio.messages.Bucket;
import org.assertj.core.util.Lists;import java.util.List;/*** @author yue.wu* @description TODO* @date 2022/10/27 10:00*/
public class ObjectStorageMinIOUtil {public ObjectStorageMinIOUtil() {}/*** 获取Minio客户端** @param endpoint        String* @param accessKeyId     String* @param accessKeySecret String* @return MinioClient Minio客户端* @author yue.wu* @date 2022/10/27 10:02*/public static MinioClient getMinioClient(String endpoint, String accessKeyId, String accessKeySecret) {return MinioClient.builder().endpoint(endpoint).credentials(accessKeyId, accessKeySecret).build();}/*** 查询Bucket是否存在** @param minioClient minio客户端* @param bucketName  bucket名称* @return Boolean Bucket是否存在* @author yue.wu* @date 2022/10/27 10:04*/public Boolean existBucket(MinioClient minioClient, String bucketName) {try {return minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());} catch (Exception e) {e.printStackTrace();}return false;}/*** 创建Bucket** @param minioClient minio客户端* @param bucketName  bucket名称* @return Boolean 创建成功/失败* @author yue.wu* @date 2022/10/27 10:07*/public Boolean makeBucket(MinioClient minioClient, String bucketName) {try {minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());} catch (Exception e) {e.printStackTrace();return false;}return true;}/*** 删除Bucket** @param minioClient minio客户端* @param bucketName  bucket名称* @return Boolean 删除成功/失败* @author yue.wu* @date 2022/10/27 10:07*/public Boolean removeBucket(MinioClient minioClient, String bucketName) {try {minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());} catch (Exception e) {e.printStackTrace();return false;}return true;}/*** 获取Bucket列表** @param minioClient minio客户端* @return List Bucket列表* @author yue.wu* @date 2022/10/27 10:11*/public static List<Bucket> getBucketList(MinioClient minioClient) {try {return minioClient.listBuckets();} catch (Exception e) {e.printStackTrace();}return Lists.newArrayList();}}

3、亚马逊

import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.Bucket;import java.util.List;/*** @author yue.wu* @description TODO* @date 2022/10/27 10:13*/
public class ObjectStorageAWSUtil {private static final String accessKey = "";private static final String secretKey = "";private static final String endpoint = "";private static final Protocol http = Protocol.HTTP;/*** TODO** @param endpoint        String* @param accessKeyId     String* @param accessKeySecret String* @param protocol        协议类型* @return AmazonS3 S3客户端* @author yue.wu* @date 2022/10/27 11:15*/public static AmazonS3 getConnect(String endpoint, String accessKeyId, String accessKeySecret, Protocol protocol) {ValidationUtils.assertAllNotNull("param cannot be null", endpoint, accessKeyId, accessKeySecret, protocol);AmazonS3ClientBuilder client = AmazonS3ClientBuilder.standard();ClientConfiguration config = new ClientConfiguration();// 默认HTTPconfig.setProtocol(protocol);config.setConnectionTimeout(15 * 1000);// v2config.setSignerOverride("S3SignerType");// v4// config.setSignerOverride("AWSS3V4SignerType");AWSCredentials acre = new BasicAWSCredentials(accessKeyId, accessKeySecret);AWSCredentialsProvider provider = new AWSStaticCredentialsProvider(acre);AwsClientBuilder.EndpointConfiguration endpointConfig = new AwsClientBuilder.EndpointConfiguration(endpoint, null);client.setClientConfiguration(config);// client.setChunkedEncodingDisabled(true);client.setCredentials(provider);client.setEndpointConfiguration(endpointConfig);return client.build();}/*** 获取bucket列表** @param client s3客户端* @return List<Bucket> bucket列表* @author yue.wu* @date 2022/10/27 11:21*/public static List<Bucket> getBucketList(AmazonS3 client) {return ValidationUtils.assertNotNull(client, "client").listBuckets();}/*** 检查bucket是否存在** @param client     s3客户端* @param bucketName bucket名称* @return Boolean 是否存在* @author yue.wu* @date 2022/10/27 11:23*/public static Boolean existBucket(AmazonS3 client, String bucketName) {ValidationUtils.assertAllNotNull("param cannot be null", client, bucketName);return client.doesBucketExistV2(bucketName);}/*** 创建bucket** @param client     s3客户端* @param bucketName bucket名称* @return Bucket  Bucket* @author yue.wu* @date 2022/10/27 11:28*/public static Bucket createBucket(AmazonS3 client, String bucketName) {ValidationUtils.assertAllNotNull("param cannot be null", client, bucketName);return client.createBucket(bucketName);}}

4、阿里OSS

import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.Bucket;import java.util.List;/*** @author yue.wu* @description TODO* @date 2022/10/27 11:14*/
public class ObjectStorageOSSUtil {public ObjectStorageOSSUtil() {}/*** 获取OSS连接** @param endpoint        String* @param accessKeyId     String* @param accessKeySecret String* @param configuration   ClientBuilderConfiguration* @return OSS* @author yue.wu* @date 2022/8/24 9:25*/public static OSS getOssClient(String endpoint, String accessKeyId, String accessKeySecret,ClientBuilderConfiguration configuration) {return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret, configuration);}/*** 获取OSS连接** @param endpoint        String* @param accessKeyId     String* @param accessKeySecret String* @return OSS* @author yue.wu* @date 2022/8/24 9:25*/public static OSS getOssClient(String endpoint, String accessKeyId, String accessKeySecret) {return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);}/*** 获取BUCKET列表** @param client OSS* @return List<Bucket>* @author yue.wu* @date 2022/8/24 14:11*/public static List<Bucket> getBucketList(OSS client) {return client.listBuckets();}/*** 创建BUCKET** @param client     OSS* @param bucketName bucket名称* @return Bucket Bucket* @author yue.wu* @date 2022/10/27 11:27*/public static Bucket createBucket(OSS client, String bucketName) {return client.createBucket(bucketName);}}

5、校验工具(偷亚马逊的)

import java.util.Collection;/*** @author yue.wu* @description TODO* @date 2022/10/25 15:59*/
public class ValidationUtils {public ValidationUtils() {}/*** Asserts that the given object is non-null and returns it.** @param object    Object to assert on* @param fieldName Field name to display in exception message if null* @return Object if non null* @throws IllegalArgumentException If object was null*/public static <T> T assertNotNull(T object, String fieldName) throws IllegalArgumentException {if (object == null) {throw new IllegalArgumentException(String.format("%s cannot be null", fieldName));}return object;}/*** Asserts that all of the objects are null.** @throws IllegalArgumentException if any object provided was NOT null.*/public static void assertAllAreNull(String messageIfNull, Object... objects) throws IllegalArgumentException {for (Object object : objects) {if (object != null) {throw new IllegalArgumentException(messageIfNull);}}}/*** Asserts that all of the objects are null.** @throws IllegalArgumentException if any object provided was NOT null.*/public static void assertAllNotNull(String messageIfNull, Object... objects) throws IllegalArgumentException {for (Object object : objects) {if (object == null) {throw new IllegalArgumentException(messageIfNull);}}}/*** Asserts that the given number is positive (non-negative and non-zero).** @param num       Number to validate* @param fieldName Field name to display in exception message if not positive.* @return Number if positive.*/public static int assertIsPositive(int num, String fieldName) {if (num <= 0) {throw new IllegalArgumentException(String.format("%s must be positive", fieldName));}return num;}public static <T extends Collection<?>> T assertNotEmpty(T collection, String fieldName) throws IllegalArgumentException {assertNotNull(collection, fieldName);if (collection.isEmpty()) {throw new IllegalArgumentException(String.format("%s cannot be empty", fieldName));}return collection;}public static <T> T[] assertNotEmpty(T[] array, String fieldName) throws IllegalArgumentException {assertNotNull(array, fieldName);if (array.length == 0) {throw new IllegalArgumentException(String.format("%s cannot be empty", fieldName));}return array;}public static String assertStringNotEmpty(String string, String fieldName) throws IllegalArgumentException {assertNotNull(string, fieldName);if (string.isEmpty()) {throw new IllegalArgumentException(String.format("%s cannot be empty", fieldName));}return string;}}

Springboot 整合常用对象存储工具(asw s3 亚马逊云存储,minio,阿里oss)相关推荐

  1. S3(亚马逊云)工具类及使用【java】

    S3(亚马逊云)工具类及使用[java] 文章目录 前言 FileServiceImpl AmazonS3Manager S3Config 配置yml maven包 s3配置与使用 前言 提示:这里是 ...

  2. 为什么说阿里云和亚马逊云对比,阿里云的性价比比较低?

    随着云计算不断发展,我们国内主流的云计算平台也逐渐完善,尤其是阿里云,它的整体实力在国内云计算平台排名第一,同时阿里云也是国内最早从事这方面研究的公司,特别值得我们信赖. 大家都知道,阿里云背后有很大 ...

  3. ESP32 AT指令连接AWS亚马逊云

    ESP32 AT指令连接AWS亚马逊云 文章目录 ESP32 AT指令连接AWS亚马逊云 1. 概述 2. 相关资料及设备说明 3. AWS云平台接入 3.1 AWS云平台接入概述 3.2 接入AWS ...

  4. 【5000字长文】从 S3 到 DataZone,亚马逊云科技用16年讲完一个数据的故事

    亚马逊云科技 2022 re:Invent 在 Las Vegas 刚落下帷幕,和去年疫情刚结束后开的 2021 re:Invent 相比,这次的现场参展人数规模空前,官方统计超过5万.这也是 Ada ...

  5. 从 S3 到 DataZone,亚马逊云科技用16年讲完一个数据的故事

    点击上方[凌云驭势 重塑未来] 一起共赴年度科技盛宴! 2022亚马逊云科技 re:Invent 全球大会在 Las Vegas 刚落下帷幕,和去年疫情刚结束后举行的 re:Invent 2021相比 ...

  6. 亚马逊云科技Amazon S3存储与客户的“独家记忆”

    2023年3月14日是亚马逊云科技Amazon S3的17周岁生日,与这些宏大的.不可量化的概念与母题相比,Amazon S3更像是一位可靠的朋友.作为亚马逊云科技的众多服务中最热门的对象存储服务,1 ...

  7. 整合来自多个Aurora数据库数据,亚马逊云科技为用户提供数据分析一体化融合解决方案

    亚马逊云科技近日在沙利文联合头豹研究院发布的<2023年中国数据管理解决方案市场报告>中再次获评中国数据管理解决方案的领导者位置,并在增长指数和创新指数上获得最高评分.亚马逊云科技凭借其独 ...

  8. 亚马逊云科技云知识总结

    模块一: 亚马逊云科技简介 云计算就是通过互联网按需求提供IT资源并采用按需付费定价模式,一种通过互联网按需求提供IT资源的形式,采用按实际使用量付费的定价方式. 模块二 :在云中计算 云计算是怎么定 ...

  9. “成本刺客”防不胜防,如何应用亚马逊云科技驾驭云成本

    达尔文曾说过"能够生存下来的生物, 既不是最强壮的, 也不是最聪明的, 而是最能够适应变化的物种." 面对眼下经济的不确定性,很多企业在压力下,被动进入到"节衣缩食&qu ...

最新文章

  1. PMWiki安装教程
  2. C++socket编程(六):6.1 设置socket的阻塞和非阻塞
  3. failed to accept an incoming connection: connection from 127.0.0.1 rejected, allowed hosts:
  4. Kylin之Caused by :...The table :DWD_ORDER_INFO Dup key found
  5. Ubuntu 安装 gcc 过程
  6. Eclipse 安装教程附免费安装包资源
  7. 【论文翻译 arXiv 2020】异质网表示学习综述-韩家炜组
  8. Ubuntu桌面版QQ安装 Linux/UbuntuQQ安装/centos QQ安装教程 2019/10/24
  9. 电路串联和并联图解_迷惑我们很久的串联/并联谐振电路(多图、详解)
  10. cad角度怎么画_女孩都喜欢的公主抱怎么画?各种不同角度公主抱漫画素材绘画教程...
  11. python俄罗斯方块思路_python实现俄罗斯方块小游戏
  12. 详解win10开机启动慢是什么原因怎么解决
  13. 如何获取iPhone 各机型以及系统的状态栏高度进行适配
  14. Chrome Extension 介绍
  15. O - 鸣人和佐助(BFS)
  16. 3D human skeleton 数据集简易可视化
  17. 记一次Redis被攻击的事件
  18. 手气红包c语言算法,YY一个拼手气的红包算法
  19. 2021高考江门成绩查询,2021年江门高考最高分多少分 历年江门高考状元
  20. 【张其中】拥有21个超级节点的EOS,背叛了区块链的去中心化理想?

热门文章

  1. Spring Boot 使用七牛云存储图片并且使用自定义域名访问
  2. threejs效果比较好的天空和水面
  3. 机器学习——决策树(一)
  4. echarts堆叠柱状图加折线图详细介绍
  5. 微信打赏功能暗示内容付费时代渐近
  6. java 等腰三角形 * 型输出
  7. (转)赵云在长坂坡杀的都是些什么人?一一道来...
  8. STM32开发笔记71: 解决FreeRTOS任务的内存分配问题
  9. 教你查询跟踪多个快递单号物流的更新量
  10. 360极速浏览器 插件 下载位置