Skip to content

Commit

Permalink
fix(put): compute length properly in case of input stream being retri…
Browse files Browse the repository at this point in the history
…eved from a get() call

closes kestra-io/kestra#4761
  • Loading branch information
brian-mulier-p committed Oct 11, 2024
1 parent 7c084a6 commit a284593
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/io/kestra/storage/s3/S3Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,21 @@ public URI put(String tenantId, URI uri, StorageObject storageObject) throws IOE

Optional<Upload> upload;

Long length = (long) data.available();
if (data instanceof ResponseInputStream<?> responseInputStream && responseInputStream.response() instanceof GetObjectResponse getObjectResponse) {
length = getObjectResponse.contentLength();
}
if (length == Integer.MAX_VALUE) {
length = null;
}

UploadRequest.Builder uploadRequest = UploadRequest.builder()
.putObjectRequest(request)
.requestBody(AsyncRequestBody.fromInputStream(
data,
// If available bytes are equals to Integer.MAX_VALUE, then available bytes may be more than Integer.MAX_VALUE.
// We set to null in this case, otherwise we would be limited to 2GB.
data.available() == Integer.MAX_VALUE ? null : (long) data.available(),
length,
Executors.newSingleThreadExecutor()
));

Expand Down

0 comments on commit a284593

Please sign in to comment.