title: Download file from URL and upload it to AWS S3 without saving into memory using AWS SDK for Java, version 2
body: <p>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.
  <a href="https://stackoverflow.com/questions/22186979/download-file-from-url-and-upload-it-to-aws-s3-without-saving-node-js">I found the this discussion on same topic using 'Node.js'</a></p>
  <hr />
  <p>My Code to Fetch the file in inputStream</p>
  <hr />
  <pre><code>HttpClient client = HttpClient.newBuilder().build();
  URI uri = URI.create(&quot;{myUrl}&quot;);
  HttpRequest request = HttpRequest.newBuilder().uri(uri).build();
  InputStream is = client.send(request, HttpResponse.BodyHandlers.ofInputStream()).body();
  </code></pre>
  <hr />
  <p>Code I tried to insert into S3, but I don't have content_length</p>
  <hr />
  <pre><code>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));
  
  </code></pre>