fix(s3): open an object's metadata and body stream together for CloudFront
The streaming change from upstream (#5278) serves S3 origins through S3Service.openObject, which upstream added in a larger disk-streaming rework (#4691) not taken here. This adds the same method on top of the existing openObjectStream.
This commit is contained in:
@@ -1332,6 +1332,23 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/** An object's metadata together with an open stream of its body; the caller closes it. */
|
||||
public record ObjectRead(S3Object object, InputStream body) implements java.io.Closeable {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
body.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@link #getObject}, but the body is an open stream instead of a byte array, so a large
|
||||
* object is served without being read into the heap.
|
||||
*/
|
||||
public ObjectRead openObject(String bucketName, String key, String versionId) {
|
||||
S3Object object = getObjectMetadata(bucketName, key, versionId);
|
||||
return new ObjectRead(object, openObjectStream(bucketName, key, versionId));
|
||||
}
|
||||
|
||||
public InputStream openObjectStream(String bucketName, String key, String versionId) {
|
||||
getObjectMetadata(bucketName, key, versionId);
|
||||
String bucketOwnerAccount = resolveBucketEntry(bucketName)
|
||||
|
||||
Reference in New Issue
Block a user