title: Uploading Base64 encoded image to Amazon s3 using java
body: <p>I am trying to upload files to Amazon S3 storage using Amazon’s Java API for it. The code is </p>
  
  <pre><code>Byte[] b = data.getBytes();
  InputStream stream  = new ByteArrayInputStream(b);
  //InputStream stream = new FileInputStream(new File("D:/samples/test.txt"));
  AWSCredentials credentials = new BasicAWSCredentials("&lt;key&gt;", "&lt;key1&gt;");
  AmazonS3 s3client = new AmazonS3Client(credentials);
  s3client.putObject(new PutObjectRequest("myBucket",name,stream, new ObjectMetadata()));
  </code></pre>
  
  <p>When I run the code after commenting the first two lines and uncommenting the third one, ie <code>stream</code> is a <code>FileoutputStream</code>, the file is uploaded correctly. But when <code>data</code> is a base64 encoded String, which is image data, the file is uploaded but image is corrupted.
  Amazon documentation says I need to create and attach a POST policy and signature for this to work. How I  can do that in java? I am not using an <code>html</code> form for uploading. </p>