|
|
|
@ -15,6 +15,7 @@ import com.amazonaws.services.s3.model.ObjectMetadata;
|
|
|
|
|
import com.amazonaws.services.s3.model.PutObjectRequest; |
|
|
|
|
import com.amazonaws.services.s3.model.S3Object; |
|
|
|
|
import com.amazonaws.services.s3.model.S3ObjectSummary; |
|
|
|
|
import com.amazonaws.util.IOUtils; |
|
|
|
|
import com.fanruan.api.log.LogKit; |
|
|
|
|
import com.fanruan.api.util.StringKit; |
|
|
|
|
import com.fr.io.repository.FineFileEntry; |
|
|
|
@ -56,6 +57,8 @@ public class S3ResourceRepository extends BaseResourceRepository {
|
|
|
|
|
amazonS3ClientBuilder = amazonS3ClientBuilder.enablePathStyleAccess(); |
|
|
|
|
} |
|
|
|
|
ClientConfiguration clientConfiguration = new ClientConfiguration(); |
|
|
|
|
clientConfiguration.setMaxConnections(config.getMaxConnections()); |
|
|
|
|
LogKit.info("Max connections is {}!", clientConfiguration.getMaxConnections()); |
|
|
|
|
if (StringUtils.isNotEmpty(config.getSignerOverride())) { |
|
|
|
|
clientConfiguration.setSignerOverride(config.getSignerOverride()); |
|
|
|
|
} |
|
|
|
@ -128,6 +131,8 @@ public class S3ResourceRepository extends BaseResourceRepository {
|
|
|
|
|
try { |
|
|
|
|
return s3.getObject(request).getObjectContent(); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
LogKit.error("[S3] Failed to read file {}", filePath); |
|
|
|
|
LogKit.error(e.getMessage(), e); |
|
|
|
|
return new ByteArrayInputStream(new byte[0]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -341,6 +346,8 @@ public class S3ResourceRepository extends BaseResourceRepository {
|
|
|
|
|
S3Object s3Object = s3.getObject(bucket, path); |
|
|
|
|
if (s3Object != null) { |
|
|
|
|
try { |
|
|
|
|
//s3Object要全部读完,否则会有警告
|
|
|
|
|
IOUtils.copy(s3Object.getObjectContent(), new NullOutputStream()); |
|
|
|
|
return s3Object.getObjectMetadata().getLastModified().getTime(); |
|
|
|
|
} finally { |
|
|
|
|
s3Object.close(); |
|
|
|
|