title: s3 upload from base64 using Lambda
body: <p>I have the following code: </p>
  
  <pre><code>import base64
  imgdata = base64.b64decode(new_string)
  filename = 'image.jpg'  # I assume you have a way of picking unique filenames
  with open(filename, 'wb') as f:
      f.write(imgdata)
  </code></pre>
  
  <p>It saves a file as jpg and I can open it. </p>
  
  <p>How can I upload this to s3 bucket, or any other service, and return a URL Security is not an issue. </p>
  
  <p>I tried </p>
  
  <pre><code>    try:
      convertedFileString = fstring.replace('-', '+').replace('_','/').replace(',','=')
      imgdata = base64.b64decode(new_string)
       # I assume you have a way of picking unique filenames
      with open(filename, 'wb') as f:
          s3 = boto3.resource('s3')
          bucket = s3.Bucket('ag-grid')
          bucket.put_object(Key=filename, Body=f)
  except Exception as e:
      return {
              'statusCode': 500,  
              'body': str(e)
      }
  </code></pre>