I am writing a code that will download a file from URL and upload it to S3, but I don't want it to be stored temporarily in file or memory, I am downloading through 'InputStream' but AWS s3 requires the file size which I don't have from 'InputStream' is there any other way. I found the this discussion on same topic using 'Node.js'
My Code to Fetch the file in inputStream
HttpClient client = HttpClient.newBuilder().build();
URI uri = URI.create("{myUrl}");
HttpRequest request = HttpRequest.newBuilder().uri(uri).build();
InputStream is = client.send(request, HttpResponse.BodyHandlers.ofInputStream()).body();
Code I tried to insert into S3, but I don't have content_length
S3Client s3Client = S3Client.builder().build();
PutObjectRequest objectRequest = PutObjectRequest.builder()
.bucket(BUCKET_NAME)
.key(KEY)
.build();
PutObjectResponse por = s3Client.putObject(objectRequest, RequestBody.fromInputStream(is,content_length));