初始化AmazonS3
配置用常量
private static String accessKey = "youraccessKey";
private static String secretKey = "yoursecretKey ";
private static String endpoint = "yourendpoint ";
private static String bucketName = "yourbucketName";
private static String region = "yourregion ";
初始化S3
public static AmazonS3 getS3(){
LOG.info("JDOSSUtil.getS3 start...");
ClientConfiguration config = new ClientConfiguration();
AwsClientBuilder.EndpointConfiguration endpointConfig =
new AwsClientBuilder.EndpointConfiguration(endpoint, region);
AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey,secretKey);
AWSCredentialsProvider awsCredentialsProvider = new AWSStaticCredentialsProvider(awsCredentials);
/** 初始化AmazonS3 */
AmazonS3 s3 = AmazonS3Client.builder()
.withEndpointConfiguration(endpointConfig)
.withClientConfiguration(config)
.withCredentials(awsCredentialsProvider)
.disableChunkedEncoding()
.withPathStyleAccessEnabled(true)
.build();
LOG.info("JDOSSUtil.getS3 end...");
return s3;
}
京东OSS直接用的 AmazonS3 OSS , jar包连名字都没改可能直接买的代码吧,估计里面就把endpoint,region这些东西改成自己的服务器而已 虽然这段是京东OSS上用的 但我估计亚马逊也能拿过来直接用