Skip to content

Commit

Permalink
Fix "Content-MD5 OR x-amz-checksum- HTTP header is required for Put P…
Browse files Browse the repository at this point in the history
…art requests with Object Lock parameters" error. Added "Content-MD5" header as x-amz-checksum-sha256 causes "Checksum Type mismatch occurred, expected checksum Type: null, actual checksum Type: sha256." for parts. Fix #15557.
  • Loading branch information
dkocher committed Mar 8, 2024
1 parent 984971a commit a4826c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 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

0 comments on commit a4826c8

Please sign in to comment.