浏览代码

fix doesObjectExist

xiewj 1 周之前
父节点
当前提交
d4f5308fb5

+ 4 - 2
4dkankan-utils-filestorage/src/main/java/com/fdkankan/filestorage/StorageAutoConfiguration.java

@@ -80,8 +80,10 @@ public class StorageAutoConfiguration {
     public AmazonS3 amazonS3Client(AwsProperties properties) {
         BasicAWSCredentials awsCreds = new BasicAWSCredentials(properties.getAccessKey(), properties.getAccessKeySecret());
         ClientConfiguration clientConfiguration = new ClientConfiguration();
-        clientConfiguration.setMaxErrorRetry(4);
-        clientConfiguration.setMaxConnections(200);
+        clientConfiguration.setMaxErrorRetry(5);
+        clientConfiguration.setMaxConnections(300);
+        clientConfiguration.setConnectionTimeout(5000);
+        clientConfiguration.setSocketTimeout(5000);
         AmazonS3 s3 = AmazonS3ClientBuilder.standard()
                 .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
                 .withRegion(Regions.EU_WEST_2)

+ 2 - 3
4dkankan-utils-filestorage/src/main/java/com/fdkankan/filestorage/aws/AwsTemplate.java

@@ -257,6 +257,7 @@ public class AwsTemplate implements FileStorageTemplate {
         } finally {
             if (content != null) {
                 try {
+                    object.close();
                     content.close();
                 } catch (IOException e) {
                     // Ignore
@@ -381,9 +382,7 @@ public class AwsTemplate implements FileStorageTemplate {
             if("/".equals(keyName.substring(0,1))){
                 keyName = keyName.substring(1);
             }
-            GetObjectRequest request  = new GetObjectRequest(bucket,keyName);
-            S3Object object = amazonS3Client.getObject(request);
-            return true;
+            return amazonS3Client.doesObjectExist(bucket,keyName);
         } catch (AmazonServiceException e) {
             if (e.getErrorCode().equalsIgnoreCase("NoSuchKey")) {
                 log.error("NoSuchKey", e.getMessage());