title: Image uploaded to S3 becomes corrupted
body: <p>I’m having issues uploading a file from postman to aws lambda + s3. If I understand correctly the image has to be a base64 string and send via JSON to work with lambda and API Gateway so I converted an image to a base64 and I’m using the base64 string in postman</p>
  <p><a href="https://i.stack.imgur.com/YjUih.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YjUih.png" alt="enter image description here" /></a></p>
  <p>The file uploads to S3, but when I download the s3 object and open it I get</p>
  <p><a href="https://i.stack.imgur.com/GgYhd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GgYhd.png" alt="enter image description here" /></a></p>
  <p>So I don’t think I’m uploading it correctly. I’ve used a base64 to image converter and the image appears so the base64 string is correct before sending it via postman so something in my setup is off. What am I doing wrong? I appreciate the help!</p>
  <p>upload.js</p>
  <pre><code>const AWS = require('aws-sdk');
  const s3 = new AWS.S3();
  exports.handler = async (event, context, callback) =&gt; {
      let data = JSON.parse(event.body);
      let file = data.base64String;
  
  
      const s3Bucket = &quot;upload-test3000&quot;;
      const objectName = &quot;helloworld.jpg&quot;;
      const objectData = data.base64String;
      const objectType = &quot;image/jpg&quot;;
      try {
          const params = {
              Bucket: s3Bucket,
              Key: objectName,
              Body: objectData,
              ContentType: objectType
          };
          const result = await s3.putObject(params).promise();
          return sendRes(200, `File uploaded successfully at https:/` + s3Bucket + `.s3.amazonaws.com/` + objectName);
  
      } catch (error) {
          return sendRes(404, error);
      }
  };
  const sendRes = (status, body) =&gt; {
      var response = {
          statusCode: status,
          headers: {
              &quot;Content-Type&quot;: &quot;application/json&quot;,
              &quot;Access-Control-Allow-Headers&quot;: &quot;Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token&quot;,
              &quot;Access-Control-Allow-Methods&quot;: &quot;OPTIONS,POST,PUT&quot;,
              &quot;Access-Control-Allow-Credentials&quot;: true,
              &quot;Access-Control-Allow-Origin&quot;: &quot;*&quot;,
              &quot;X-Requested-With&quot;: &quot;*&quot;
          },
          body: body
      };
      return response;
  };
  </code></pre>
  <p>.png</p>