Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: uploading a data:image/imagetype,base64 in perl

by Mr. Muskrat (Canon)
on Dec 04, 2017 at 20:14 UTC ( #1204893=note: print w/replies, xml ) Need Help??


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

It looks like you need to remove 'data:image/png;base64,' from the beginning of $fetch_photo before you pass it into decode_base64.

Update: Here's an updated script that improves upon how you were doing things. It passed cursory testing.

#!/usr/bin/perl use strict; use warnings; use CGI; use MIME::Base64; my $arg = new CGI; my $fetch_photo = $arg->param('imagedata'); my ($data, $base64) = split /,/, $fetch_photo; my ($type) = $data =~ m!data:image/(\w+);base64!; my $decoded = MIME::Base64::decode_base64($base64); my $filename = int(rand(1000)) . '.' . $type; open(my $file, '>', "img/$filename") or die 'err'; # 3 argument open binmode $file; print $file $decoded; close($file);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1204893]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2022-05-25 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (84 votes). Check out past polls.

    Notices?