Java AWS s3: How to set and upload content with Md5 pre signed url
<p>I am trying to generate an AWS presigned url with MD5 content. The url is generate but when I uses it to upload the content it fails with HTTP 403. error</p>

<p>Java code to generate the presigned URL is as below:</p>

<pre><code>    GeneratePresignedUrlRequest generatePresignedUrlRequest = new     GeneratePresignedUrlRequest(bucketName, key, httpMethod);
    byte[] resultByte = DigestUtils.md5(/*byte array*/);    
    String streamMD5 = new String(java.util.Base64.getEncoder().encode(resultByte));
    generatePresignedUrlRequest.setContentMd5(streamMD5);
    s3Client.generatePresignedUrl(generatePresignedUrlRequest);
</code></pre>

<p>Java code to upload data using pre signed url:</p>

<pre><code>   HttpURLConnection connection;
    try {
        connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);
        connection.setRequestMethod("PUT");
        OutputStream output = connection.getOutputStream();
        output.write(getImage());
        output.flush();
        assertEquals(OK, connection.getResponseCode());
    } catch (IOException e) {
        LOGGER.info("Exception: {}", e);
    }
</code></pre>

<p>I am not sure what need to be added on upload code to make it work.</p>