Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by Mr. Muskrat (Canon)
on Dec 04, 2017 at 20:14 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2024-04-18 10:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found