You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/09/30 17:21:10 UTC
[camel] 02/02: CAMEL-17027: camel-aws-s3 producer in put mode
should use input stream with computed content length instead of reading
into byte array in memory.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch CAMEL-17024
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 5a865d0cf1c956a1e7cbe7ed51e5dd93491b2405
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Sep 30 19:20:28 2021 +0200
CAMEL-17027: camel-aws-s3 producer in put mode should use input stream with computed content length instead of reading into byte array in memory.
---
.../org/apache/camel/component/aws2/s3/AWS2S3Producer.java | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
index 8427993..6044db9 100644
--- a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
+++ b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
@@ -42,7 +42,6 @@ import org.slf4j.LoggerFactory;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.core.ResponseInputStream;
-import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.core.sync.ResponseTransformer;
import software.amazon.awssdk.regions.Region;
@@ -288,7 +287,7 @@ public class AWS2S3Producer extends DefaultProducer {
}
}
- doPutObject(exchange, putObjectRequest, objectMetadata, inputStream);
+ doPutObject(exchange, putObjectRequest, objectMetadata, inputStream, contentLength);
} finally {
IOHelper.close(inputStream);
}
@@ -300,7 +299,7 @@ public class AWS2S3Producer extends DefaultProducer {
private void doPutObject(
Exchange exchange, PutObjectRequest.Builder putObjectRequest, Map<String, String> objectMetadata,
- InputStream inputStream) {
+ InputStream inputStream, long contentLength) {
final String bucketName = AWS2S3Utils.determineBucketName(exchange, getConfiguration());
final String key = AWS2S3Utils.determineKey(exchange, getConfiguration());
putObjectRequest.bucket(bucketName).key(key).metadata(objectMetadata);
@@ -350,8 +349,9 @@ public class AWS2S3Producer extends DefaultProducer {
LOG.trace("Put object [{}] from exchange [{}]...", putObjectRequest, exchange);
- PutObjectResponse putObjectResult = getEndpoint().getS3Client().putObject(putObjectRequest.build(),
- RequestBody.fromBytes(SdkBytes.fromInputStream(inputStream).asByteArray()));
+ RequestBody rb = RequestBody.fromInputStream(inputStream, contentLength);
+
+ PutObjectResponse putObjectResult = getEndpoint().getS3Client().putObject(putObjectRequest.build(), rb);
LOG.trace("Received result [{}]", putObjectResult);