question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide option to get blob instead of Base64 URL

See original GitHub issue

In iOS Safari when I choose a file, crop it, and submit using Croppie, a message appears saying “A problem occurred with this webpage so it was reloaded” and a prompt saying “Are you sure you want to submit this form again?” appears, often resulting in the same message appearing, and sometimes it just submits the form and works. In all other browsers I’ve tried, Android, Chrome, etc., it has worked just fine.

My javascript is based off of the examples on http://foliotek.github.io/Croppie/

Javascript code (imageupload.js):

$( document ).ready(function() {
   var $uploadCrop;

   function readFile(input) {
      if (input.files && input.files[0]) {
         var reader = new FileReader();
         reader.onload = function (e) {
            $uploadCrop.croppie('bind', {
               url: e.target.result
            });
            $('.upload-demo').addClass('ready');
         }
         reader.readAsDataURL(input.files[0]);
      }
   }

   $uploadCrop = $('#upload-demo').croppie({
      viewport: {
         width: 530,
         height: 300,
         type: 'square'
      },
      boundary: {
         width: 600,
         height: 370
      }
   });

   $('#upload').on('change', function () { readFile(this); });
   $('.upload-result').on('click', function (ev) {
      $uploadCrop.croppie('result', {
         type: 'canvas',
         size: 'original'
      }).then(function (resp) {
         $('#image-data').val(resp);
         $('#form').submit();
      });
   });

});

html code (upload.html):

<html>
   <head>
      <title>upload</title>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
      <script src="node_modules/croppie/croppie.js"></script>
      <script src="imageupload.js"></script>
      <link rel="stylesheet" href="node_modules/croppie/croppie.css" />
   </head>
   <body>

      <form enctype="multipart/form-data" action="/handleupload/" id="form" method="post">
         <input type="file" id="upload" value="Choose a file">
         <div id="upload-demo"></div>
         <input type="hidden" id="image-data" name="image-data">
         <a href="#" class="upload-result">Send</a>
      </form>

   </body>
</html>

Am I doing this correctly?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
thedustinsmithcommented, Oct 21, 2016

Will be in 2.4.0

1reaction
thedustinsmithcommented, Sep 21, 2016

@Zapnologica It’s in master. You can be a guinea pig - since you seem pretty against base64.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating a BLOB from a Base64 string in JavaScript
I would like to create a blob: URL containing this data and display it to the user: const blob = new Blob(????, {type:...
Read more >
Converting a base64 string to a blob in JavaScript - Ionic Blog
Easy as one, two. First, pass a base64 string to fetch : const base64Data = "aGV5IHRoZXJl"; const base64 = await fetch(base64Data);
Read more >
Blob - The Modern JavaScript Tutorial
An alternative to URL.createObjectURL is to convert a Blob into a base64-encoded string. That encoding represents binary data as a string of ...
Read more >
How to convert blob to base64 encoding using JavaScript
Example: Convert Blob to Base64 Encoded String using FileReader API. The FileReader.readAsDataURL() reads the contents of the specified Blob ...
Read more >
FileReader.readAsDataURL() - Web APIs | MDN
Note: The blob's result cannot be directly decoded as Base64 without first removing the Data-URL declaration preceding the Base64-encoded ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found