title: How to convert a base64 string into a file?
body: <p>I used a jquery plugin to crop images. The plugin will crop the image and give it to me as a base64 encoded string. In order to upload it to S3, I need to convert this into a file and pass the file into the upload function. How can I do this? I tried a lot of things including decoding the string using <code>atob</code>. None worked.</p>
  
  <p>Here's the code of the cropping plugin ('croppie') which gives me the encoded string :</p>
  
  <pre><code>imageCropper.croppie('result', {
      type: 'canvas',
      size: 'viewport',
      format: 'jpeg'
  }).then(function (resp) {
    updateAvatar(resp);
  });
  </code></pre>
  
  <p>I pass it to a function called <code>updateAvatar</code>. Here's the updateAvatar function :</p>
  
  <pre><code>updateAvatar({Meteor, Slingshot}, avatar) {
    const uploader = new Slingshot.Upload('userAvatarUpload');
  
    uploader.send(avatar, function (error, downloadUrl) {
      if (error) {
        // Log service detailed response.
        console.error('Error uploading', uploader.xhr.response);
        console.log(error);
      }
      else {
        console.log('uploaded', downloadUrl);
      }
    });
  }
  </code></pre>
  
  <p>The uploader.send function expects a file or a url. It won't accept my encoded string.</p>
  
  <p>The plugin which I use to upload files to S3 : <a href="https://github.com/CulturalMe/meteor-slingshot" rel="nofollow">https://github.com/CulturalMe/meteor-slingshot</a></p>