title: s3.upload() works but uploads broken image
body: <p>I've got a Lambda function in AWS that is hooked up to a POST method which basically takes an image URL and uploads the image to an S3 bucket.</p>
  
  <p>My Lambda function looks like this:</p>
  
  <pre><code>var s3 = new AWS.S3();
  
  exports.handler = (event, context, callback) =&gt; {
    let encodedImage = JSON.parse(event.body).user_avatar;
    let decodedImage = Buffer.from(encodedImage, 'base64');
    var filePath = "avatars/" + event.queryStringParameters.username + ".jpg"
  
    var params = {
      "Body": decodedImage,
      "Bucket": "MYBUCKETNAME.com",
      "Key": filePath
    };
    s3.upload(params, function (err, data) {
      if (err) {
        callback(err, null);
      } else {
        let response = {
          "statusCode": 200,
          "headers": {
            "my_header": "my_value"
          },
          "body": JSON.stringify(data),
          "isBase64Encoded": false
        };
        callback(null, response);
      }
    });
  };
  </code></pre>
  
  <p>It seems to upload the image to the bucket specified, but when I view the image it seems to be broken.</p>
  
  <p><a href="https://i.stack.imgur.com/pQIrh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pQIrh.png" alt="enter image description here"></a></p>
  
  <p>I'm very inexperienced with using AWS for anything outside of the GUI they provide. If anyone has any idea of what might be going on I'd appreciate any help. Thanks in advance!</p>