S3 calculated md5 and store bitstream md5 on Multipart upload

This commit is contained in:
Nathan Buckingham
2021-12-13 16:18:16 -05:00
parent 0b95376e5d
commit 6c5e568543

View File

@@ -181,16 +181,20 @@ public class S3BitStoreService implements BitStoreService {
try { try {
FileUtils.copyInputStreamToFile(in, scratchFile); FileUtils.copyInputStreamToFile(in, scratchFile);
long contentLength = scratchFile.length(); long contentLength = scratchFile.length();
String localChecksum = org.dspace.curate.Utils.checksum(scratchFile, "MD5");
TransferManager tm = TransferManagerBuilder.standard() TransferManager tm = TransferManagerBuilder.standard()
.withAlwaysCalculateMultipartMd5(true)
.withS3Client(s3Service) .withS3Client(s3Service)
.build(); .build();
Upload upload = tm.upload(bucketName, key, scratchFile); Upload upload = tm.upload(bucketName, key, scratchFile);
UploadResult result = upload.waitForUploadResult();
upload.waitForUploadResult();
bitstream.setSizeBytes(contentLength); bitstream.setSizeBytes(contentLength);
bitstream.setChecksum(result.getETag()); bitstream.setChecksum(localChecksum);
bitstream.setChecksumAlgorithm(CSA); bitstream.setChecksumAlgorithm(CSA);
scratchFile.delete(); scratchFile.delete();
@@ -199,8 +203,8 @@ public class S3BitStoreService implements BitStoreService {
log.error("put(" + bitstream.getInternalId() + ", is)", e); log.error("put(" + bitstream.getInternalId() + ", is)", e);
throw new IOException(e); throw new IOException(e);
} finally { } finally {
if (scratchFile.exists()) { if (!scratchFile.delete()) {
scratchFile.delete(); scratchFile.deleteOnExit();
} }
} }
} }