Hi, I am using a Cropit.js to let my users customize their uploaded images but the problem is, it uses: data:image/png;base64,iVBORw0k... so what i did is i've used the MIME::Base64 Perl Module. So here's how i did it:
<!-- MY HTML FORM --> <form action="upload.pl" method="post" enctype="multipart/form-data"> <div class="image-editor"> <input type="file" class="cropit-image-input" /> <div class="cropit-preview"></div> <div class="image-size-label"> Resize Image: </div> <input type="range" class="cropit-image-zoom-input" /> <input type="hidden" name="imagedata" class="hidden-image-data" /> <button type="submit">save</button> </div> </form> <!-- END OF HTML FORM -->
Here's my Perl Code:
#!/usr/bin/perl use strict; use warnings; use CGI; use MIME::Base64; my $arg=new CGI; my $fetch_photo=$arg->param('imagedata'); my $decoded=MIME::Base64::decode_base64($fetch_photo); my $filename; $filename=int rand(1000).".png" if $fetch_photo=~/png/; $filename=int rand(1000).".jpg" if $fetch_photo=~/jpg/; open(FILE, ">img/$filename") or die 'err'; binmode FILE; print FILE $decoded; close(FILE);
It keeps uploading a unreadable/corrupted image file please help! thank you.

In reply to uploading a data:image/imagetype,base64 in perl by SASBurns

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.