|
|
|
@ -57,6 +57,8 @@ public class S3ResourceRepository extends BaseResourceRepository {
|
|
|
|
|
|
|
|
|
|
public static final String HTTP = "http:"; |
|
|
|
|
|
|
|
|
|
private final boolean preserveMetadata; |
|
|
|
|
|
|
|
|
|
private final AmazonS3 s3; |
|
|
|
|
private final String bucket; |
|
|
|
|
|
|
|
|
@ -83,6 +85,7 @@ public class S3ResourceRepository extends BaseResourceRepository {
|
|
|
|
|
amazonS3ClientBuilder = amazonS3ClientBuilder.withClientConfiguration(clientConfiguration); |
|
|
|
|
this.s3 = amazonS3ClientBuilder.build(); |
|
|
|
|
this.bucket = config.getBucket(); |
|
|
|
|
this.preserveMetadata = config.isPreserveMetadata(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -158,19 +161,21 @@ public class S3ResourceRepository extends BaseResourceRepository {
|
|
|
|
|
if (length > MULTIPART_UPLOAD_LIMIT) { |
|
|
|
|
multipartUpload(path, new ByteArrayInputStream(data)); |
|
|
|
|
} else { |
|
|
|
|
ObjectMetadata metadata; |
|
|
|
|
try { |
|
|
|
|
metadata = s3.getObjectMetadata(bucket, path); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
ObjectMetadata metadata = null; |
|
|
|
|
if (preserveMetadata) { |
|
|
|
|
try { |
|
|
|
|
metadata = s3.getObjectMetadata(bucket, path); |
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (metadata == null) { |
|
|
|
|
metadata = new ObjectMetadata(); |
|
|
|
|
String mimeType = URLConnection.guessContentTypeFromName(path); |
|
|
|
|
if (mimeType != null) { |
|
|
|
|
metadata.setContentType(mimeType); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (metadata != null) { |
|
|
|
|
metadata.setContentLength(length); |
|
|
|
|
} |
|
|
|
|
metadata.setContentLength(length); |
|
|
|
|
s3.putObject(bucket, path, new ByteArrayInputStream(data), metadata); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -269,7 +274,7 @@ public class S3ResourceRepository extends BaseResourceRepository {
|
|
|
|
|
try { |
|
|
|
|
s3.putObject(req); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
LogKit.error("[S3] Failed to create parent path {}", path); |
|
|
|
|
LogKit.error("[S3] Failed to create path {}", path); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|