diff --git a/src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java b/src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java index 560d81e..2aecad2 100644 --- a/src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java +++ b/src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java @@ -13,6 +13,8 @@ import com.fr.io.context.info.RepositoryProfile; import com.fr.io.repository.ResourceRepository; import com.fr.stable.StringUtils; +import static com.fanruan.fs.s3.repository.core.S3ResourceRepository.HTTP; + /** * @author richie * @version 10.0 @@ -42,16 +44,19 @@ public class S3RepositoryFactory extends ConfigRepositoryFactory { BasicAWSCredentials credentials = new BasicAWSCredentials(config.getAccessKeyId(), config.getPassword()); AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3ClientBuilder.standard() .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(config.getEndPoint(), config.getRegion())) - .withCredentials(new AWSStaticCredentialsProvider(credentials)); + .withCredentials(new AWSStaticCredentialsProvider(credentials)).disableChunkedEncoding(); if (config.isEnablePathStyleAccess()) { amazonS3ClientBuilder = amazonS3ClientBuilder.enablePathStyleAccess(); } + ClientConfiguration clientConfiguration = new ClientConfiguration(); if (StringUtils.isNotEmpty(config.getSignerOverride())) { - ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setSignerOverride(config.getSignerOverride()); + } + LogKit.debug("[S3] endpoint is {}", config.getEndPoint()); + if (config.getEndPoint().startsWith(HTTP)) { clientConfiguration.setProtocol(Protocol.HTTP); - amazonS3ClientBuilder = amazonS3ClientBuilder.withClientConfiguration(clientConfiguration); } + amazonS3ClientBuilder = amazonS3ClientBuilder.withClientConfiguration(clientConfiguration); AmazonS3 s3 = amazonS3ClientBuilder.build(); s3.listObjects(config.getBucket()); } catch (Exception e) { diff --git a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java index 66f907e..093dc20 100644 --- a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java +++ b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java @@ -38,6 +38,8 @@ public class S3ResourceRepository extends BaseResourceRepository { private static final String DELIMITER = "/"; + public static final String HTTP = "http:"; + private final AmazonS3 s3; private final String bucket; @@ -55,7 +57,10 @@ public class S3ResourceRepository extends BaseResourceRepository { if (StringUtils.isNotEmpty(config.getSignerOverride())) { clientConfiguration.setSignerOverride(config.getSignerOverride()); } - clientConfiguration.setProtocol(Protocol.HTTP); + LogKit.debug("[S3] endpoint is {}", config.getEndPoint()); + if (config.getEndPoint().startsWith(HTTP)) { + clientConfiguration.setProtocol(Protocol.HTTP); + } amazonS3ClientBuilder = amazonS3ClientBuilder.withClientConfiguration(clientConfiguration); this.s3 = amazonS3ClientBuilder.build(); this.bucket = config.getBucket();