mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 23:13:10 +00:00
S3 calculated md5 and store bitstream md5 on Multipart upload
This commit is contained in:
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user