Skip to content

Commit

Permalink
Merge pull request #15699 from iterate-ch/bugfix/GH-15557-Content-MD5
Browse files Browse the repository at this point in the history
Fix #15557 for multipart uploads
  • Loading branch information
dkocher authored Mar 8, 2024
2 parents 984971a + 2d4b8e7 commit a480ac3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import ch.cyberduck.core.transfer.TransferStatus;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHeaders;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jets3t.service.ServiceException;
Expand Down Expand Up @@ -237,6 +238,10 @@ public MultipartPart call() throws BackgroundException {
break;
}
status.setSegment(true);
final HashMap<String, String> metadata = new HashMap<>(status.getMetadata());
metadata.put(HttpHeaders.CONTENT_MD5, ChecksumComputeFactory.get(HashAlgorithm.md5)
.compute(local.getInputStream(), status).base64);
status.setMetadata(metadata);
final StorageObject part = S3MultipartUploadService.super.upload(
file, local, throttle, counter, status, overall, status, callback);
if(log.isInfoEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import ch.cyberduck.core.transfer.TransferStatus;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHeaders;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -117,6 +118,7 @@ private final class MultipartOutputStream extends OutputStream {
private final AtomicReference<ServiceException> canceled = new AtomicReference<>();
private final AtomicReference<MultipartCompleted> response = new AtomicReference<>();

private final ChecksumCompute md5 = ChecksumComputeFactory.get(HashAlgorithm.md5);
private final ChecksumCompute sha256 = ChecksumComputeFactory.get(HashAlgorithm.sha256);

private Long offset = 0L;
Expand Down Expand Up @@ -150,6 +152,7 @@ public MultipartPart call() throws BackgroundException {
}
status.setSegment(true);
final S3Object part = new S3WriteFeature(session, acl).getDetails(file, status);
part.addMetadata(HttpHeaders.CONTENT_MD5, md5.compute(new ByteArrayInputStream(content, off, len), status).base64);
try {
final Path bucket = containerService.getContainer(file);
session.getClient().putObjectWithRequestEntityImpl(
Expand Down
4 changes: 0 additions & 4 deletions s3/src/main/java/ch/cyberduck/core/s3/S3WriteFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.jets3t.service.model.MultipartUpload;
import org.jets3t.service.model.S3Object;
import org.jets3t.service.model.StorageObject;
import org.jets3t.service.utils.ServiceUtils;

import java.util.EnumSet;
import java.util.List;
Expand Down Expand Up @@ -107,9 +106,6 @@ protected S3Object getDetails(final Path file, final TransferStatus status) {
final Checksum checksum = status.getChecksum();
if(Checksum.NONE != checksum) {
switch(checksum.algorithm) {
case md5:
object.setMd5Hash(ServiceUtils.fromHex(checksum.hash));
break;
case sha256:
if(!status.isSegment()) {
object.addMetadata("x-amz-checksum-sha256", checksum.base64);
Expand Down

0 comments on commit a480ac3

Please sign in to comment.