mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(s3): preserve Content-Disposition on object responses (#408)
* feat(s3): preserve Content-Disposition on object responses * fix(s3): preserve Content-Disposition for multipart uploads * test(s3): avoid duplicate order annotations
This commit is contained in:
1 parent
3621c32b88
commit
c8797e2456
6 files changed
+138
-14
No files matched your search
@@ -397,11 +397,13 @@ public class S3Controller {
|
||||
byte[] data = decodeAwsChunked(body, contentEncoding, contentSha256);
|
||||
validateChecksumHeaders(httpHeaders, data);
|
||||
String persistedEncoding = toPersistedContentEncoding(contentEncoding);
|
||||
String contentDisposition = httpHeaders.getHeaderString("Content-Disposition");
|
||||
String cacheControl = httpHeaders.getHeaderString("Cache-Control");
|
||||
S3Object obj = s3Service.putObject(bucket, key, data, contentType, extractUserMetadata(httpHeaders),
|
||||
httpHeaders.getHeaderString("x-amz-storage-class"),
|
||||
persistedEncoding,
|
||||
lockMode, retainUntil, legalHold,
|
||||
contentDisposition,
|
||||
cacheControl);
|
||||
var resp = Response.ok().header("ETag", obj.getETag());
|
||||
if (obj.getVersionId() != null) {
|
||||
@@ -727,7 +729,9 @@ public class S3Controller {
|
||||
|
||||
if (hasQueryParam(uriInfo, "uploads")) {
|
||||
MultipartUpload upload = s3Service.initiateMultipartUpload(bucket, key, contentType,
|
||||
extractUserMetadata(httpHeaders), httpHeaders.getHeaderString("x-amz-storage-class"));
|
||||
extractUserMetadata(httpHeaders),
|
||||
httpHeaders.getHeaderString("x-amz-storage-class"),
|
||||
httpHeaders.getHeaderString("Content-Disposition"));
|
||||
String xml = new XmlBuilder()
|
||||
.raw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
|
||||
.start("InitiateMultipartUploadResult", AwsNamespaces.S3)
|
||||
@@ -1303,6 +1307,9 @@ public class S3Controller {
|
||||
if (obj.getContentEncoding() != null) {
|
||||
resp.header("Content-Encoding", obj.getContentEncoding());
|
||||
}
|
||||
if (obj.getContentDisposition() != null) {
|
||||
resp.header("Content-Disposition", obj.getContentDisposition());
|
||||
}
|
||||
if (obj.getCacheControl() != null) {
|
||||
resp.header("Cache-Control", obj.getCacheControl());
|
||||
}
|
||||
@@ -1350,6 +1357,7 @@ public class S3Controller {
|
||||
String sourceKey = decodedSource.substring(slashIndex + 1);
|
||||
|
||||
String copyContentEncoding = toPersistedContentEncoding(httpHeaders.getHeaderString("Content-Encoding"));
|
||||
String copyContentDisposition = httpHeaders.getHeaderString("Content-Disposition");
|
||||
String copyCacheControl = httpHeaders.getHeaderString("Cache-Control");
|
||||
S3Object copy = s3Service.copyObject(sourceBucket, sourceKey, destBucket, destKey,
|
||||
httpHeaders.getHeaderString("x-amz-metadata-directive"),
|
||||
@@ -1357,6 +1365,7 @@ public class S3Controller {
|
||||
httpHeaders.getHeaderString("x-amz-storage-class"),
|
||||
contentType,
|
||||
copyContentEncoding,
|
||||
copyContentDisposition,
|
||||
copyCacheControl);
|
||||
String xml = new XmlBuilder()
|
||||
.raw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
|
||||
|
||||
@@ -184,30 +184,30 @@ public class S3Service {
|
||||
|
||||
public S3Object putObject(String bucketName, String key, byte[] data,
|
||||
String contentType, Map<String, String> metadata) {
|
||||
return putObject(bucketName, key, data, contentType, metadata, null, null, null, null, null, null);
|
||||
return putObject(bucketName, key, data, contentType, metadata, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public S3Object putObject(String bucketName, String key, byte[] data,
|
||||
String contentType, Map<String, String> metadata,
|
||||
String objectLockMode, Instant retainUntilDate, String legalHoldStatus) {
|
||||
return putObject(bucketName, key, data, contentType, metadata, null, null,
|
||||
objectLockMode, retainUntilDate, legalHoldStatus, null);
|
||||
objectLockMode, retainUntilDate, legalHoldStatus, null, null);
|
||||
}
|
||||
|
||||
public S3Object putObject(String bucketName, String key, byte[] data,
|
||||
String contentType, Map<String, String> metadata, String storageClass,
|
||||
String objectLockMode, Instant retainUntilDate, String legalHoldStatus) {
|
||||
return putObject(bucketName, key, data, contentType, metadata, storageClass, null,
|
||||
objectLockMode, retainUntilDate, legalHoldStatus, null);
|
||||
objectLockMode, retainUntilDate, legalHoldStatus, null, null);
|
||||
}
|
||||
|
||||
public S3Object putObject(String bucketName, String key, byte[] data,
|
||||
String contentType, Map<String, String> metadata, String storageClass,
|
||||
String contentEncoding,
|
||||
String objectLockMode, Instant retainUntilDate, String legalHoldStatus,
|
||||
String cacheControl) {
|
||||
String contentDisposition, String cacheControl) {
|
||||
S3Object object = storeObject(bucketName, key, data, contentType, metadata, storageClass, null, null,
|
||||
objectLockMode, retainUntilDate, legalHoldStatus, contentEncoding, cacheControl);
|
||||
objectLockMode, retainUntilDate, legalHoldStatus, contentEncoding, contentDisposition, cacheControl);
|
||||
fireNotifications(bucketName, key, "ObjectCreated:Put", object);
|
||||
return object;
|
||||
}
|
||||
@@ -218,7 +218,7 @@ public class S3Service {
|
||||
private S3Object storeObject(String bucketName, String key, byte[] data,
|
||||
String contentType, Map<String, String> metadata) {
|
||||
return storeObject(bucketName, key, data, contentType, metadata, null, null, null,
|
||||
null, null, null, null, null);
|
||||
null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
private S3Object storeObject(String bucketName, String key, byte[] data,
|
||||
@@ -226,14 +226,14 @@ public class S3Service {
|
||||
S3Checksum checksum, List<Part> parts,
|
||||
String objectLockMode, Instant retainUntilDate, String legalHoldStatus) {
|
||||
return storeObject(bucketName, key, data, contentType, metadata, storageClass, checksum, parts,
|
||||
objectLockMode, retainUntilDate, legalHoldStatus, null, null);
|
||||
objectLockMode, retainUntilDate, legalHoldStatus, null, null, null);
|
||||
}
|
||||
|
||||
private S3Object storeObject(String bucketName, String key, byte[] data,
|
||||
String contentType, Map<String, String> metadata, String storageClass,
|
||||
S3Checksum checksum, List<Part> parts,
|
||||
String objectLockMode, Instant retainUntilDate, String legalHoldStatus,
|
||||
String contentEncoding, String cacheControl) {
|
||||
String contentEncoding, String contentDisposition, String cacheControl) {
|
||||
Bucket bucket = bucketStore.get(bucketName)
|
||||
.orElseThrow(() -> new AwsException("NoSuchBucket",
|
||||
"The specified bucket does not exist.", 404));
|
||||
@@ -246,6 +246,7 @@ public class S3Service {
|
||||
object.setChecksum(checksum != null ? copyChecksum(checksum) : buildChecksum(data, parts, false));
|
||||
object.setParts(copyParts(parts));
|
||||
object.setContentEncoding(contentEncoding);
|
||||
object.setContentDisposition(contentDisposition);
|
||||
object.setCacheControl(cacheControl);
|
||||
|
||||
if (bucket.isVersioningEnabled()) {
|
||||
@@ -599,14 +600,14 @@ public class S3Service {
|
||||
String metadataDirective, Map<String, String> replacementMetadata,
|
||||
String storageClass, String contentType) {
|
||||
return copyObject(sourceBucket, sourceKey, destBucket, destKey, metadataDirective,
|
||||
replacementMetadata, storageClass, contentType, null, null);
|
||||
replacementMetadata, storageClass, contentType, null, null, null);
|
||||
}
|
||||
|
||||
public S3Object copyObject(String sourceBucket, String sourceKey,
|
||||
String destBucket, String destKey,
|
||||
String metadataDirective, Map<String, String> replacementMetadata,
|
||||
String storageClass, String contentType, String contentEncoding,
|
||||
String cacheControl) {
|
||||
String contentDisposition, String cacheControl) {
|
||||
S3Object source = getObject(sourceBucket, sourceKey);
|
||||
ensureBucketExists(destBucket);
|
||||
|
||||
@@ -619,10 +620,11 @@ public class S3Service {
|
||||
String effectiveContentType = replaceMetadata && contentType != null ? contentType : source.getContentType();
|
||||
String effectiveStorageClass = storageClass != null ? storageClass : source.getStorageClass();
|
||||
String effectiveContentEncoding = replaceMetadata && contentEncoding != null ? contentEncoding : source.getContentEncoding();
|
||||
String effectiveContentDisposition = replaceMetadata && contentDisposition != null ? contentDisposition : source.getContentDisposition();
|
||||
String effectiveCacheControl = replaceMetadata && cacheControl != null ? cacheControl : source.getCacheControl();
|
||||
S3Object copy = storeObject(destBucket, destKey, source.getData(), effectiveContentType, metadata,
|
||||
effectiveStorageClass, source.getChecksum(), source.getParts(), null, null, null,
|
||||
effectiveContentEncoding, effectiveCacheControl);
|
||||
effectiveContentEncoding, effectiveContentDisposition, effectiveCacheControl);
|
||||
copy.setETag(source.getETag());
|
||||
LOG.debugv("Copied object: {0}/{1} -> {2}/{3}", sourceBucket, sourceKey, destBucket, destKey);
|
||||
fireNotifications(destBucket, destKey, "ObjectCreated:Copy", copy);
|
||||
@@ -911,17 +913,24 @@ public class S3Service {
|
||||
// --- Multipart Upload Operations ---
|
||||
|
||||
public MultipartUpload initiateMultipartUpload(String bucket, String key, String contentType) {
|
||||
return initiateMultipartUpload(bucket, key, contentType, null, null);
|
||||
return initiateMultipartUpload(bucket, key, contentType, null, null, null);
|
||||
}
|
||||
|
||||
public MultipartUpload initiateMultipartUpload(String bucket, String key, String contentType,
|
||||
Map<String, String> metadata, String storageClass) {
|
||||
return initiateMultipartUpload(bucket, key, contentType, metadata, storageClass, null);
|
||||
}
|
||||
|
||||
public MultipartUpload initiateMultipartUpload(String bucket, String key, String contentType,
|
||||
Map<String, String> metadata, String storageClass,
|
||||
String contentDisposition) {
|
||||
ensureBucketExists(bucket);
|
||||
MultipartUpload upload = new MultipartUpload(bucket, key, contentType);
|
||||
if (metadata != null) {
|
||||
upload.getMetadata().putAll(metadata);
|
||||
}
|
||||
upload.setStorageClass(ObjectAttributeName.normalizeStorageClass(storageClass));
|
||||
upload.setContentDisposition(contentDisposition);
|
||||
|
||||
if (inMemory) {
|
||||
memoryMultipartStore.put(upload.getUploadId(), new ConcurrentHashMap<>());
|
||||
@@ -1027,7 +1036,8 @@ public class S3Service {
|
||||
.toList();
|
||||
S3Checksum checksum = buildChecksum(allData, completedParts, true);
|
||||
S3Object object = storeObject(bucket, key, allData, upload.getContentType(), upload.getMetadata(),
|
||||
upload.getStorageClass(), checksum, completedParts, null, null, null);
|
||||
upload.getStorageClass(), checksum, completedParts, null, null, null,
|
||||
null, upload.getContentDisposition(), null);
|
||||
// Override the ETag with the composite multipart ETag
|
||||
object.setETag(compositeETag);
|
||||
objectStore.put(objectKey(bucket, key), object);
|
||||
@@ -1573,6 +1583,7 @@ public class S3Service {
|
||||
copy.setMetadata(new HashMap<>(source.getMetadata()));
|
||||
copy.setContentType(source.getContentType());
|
||||
copy.setContentEncoding(source.getContentEncoding());
|
||||
copy.setContentDisposition(source.getContentDisposition());
|
||||
copy.setCacheControl(source.getCacheControl());
|
||||
copy.setSize(source.getSize());
|
||||
copy.setLastModified(source.getLastModified());
|
||||
|
||||
@@ -16,6 +16,7 @@ public class MultipartUpload {
|
||||
private String key;
|
||||
private String contentType;
|
||||
private String storageClass;
|
||||
private String contentDisposition;
|
||||
private Map<String, String> metadata;
|
||||
private Instant initiated;
|
||||
private final Map<Integer, Part> parts = new ConcurrentHashMap<>();
|
||||
@@ -50,6 +51,9 @@ public class MultipartUpload {
|
||||
public String getStorageClass() { return storageClass; }
|
||||
public void setStorageClass(String storageClass) { this.storageClass = storageClass; }
|
||||
|
||||
public String getContentDisposition() { return contentDisposition; }
|
||||
public void setContentDisposition(String contentDisposition) { this.contentDisposition = contentDisposition; }
|
||||
|
||||
public Map<String, String> getMetadata() { return metadata; }
|
||||
public void setMetadata(Map<String, String> metadata) { this.metadata = metadata; }
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ public class S3Object {
|
||||
private Map<String, String> metadata;
|
||||
private String contentType;
|
||||
private String contentEncoding;
|
||||
private String contentDisposition;
|
||||
private String cacheControl;
|
||||
private long size;
|
||||
private Instant lastModified;
|
||||
@@ -82,6 +83,9 @@ public class S3Object {
|
||||
public String getContentEncoding() { return contentEncoding; }
|
||||
public void setContentEncoding(String contentEncoding) { this.contentEncoding = contentEncoding; }
|
||||
|
||||
public String getContentDisposition() { return contentDisposition; }
|
||||
public void setContentDisposition(String contentDisposition) { this.contentDisposition = contentDisposition; }
|
||||
|
||||
public String getCacheControl() { return cacheControl; }
|
||||
public void setCacheControl(String cacheControl) { this.cacheControl = cacheControl; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user