perl - change my json string in a loop -


right have json created select mysql , looks this:

$sth->execute()   or die "sql error: $dbi::errstr\n";  while (my $row = $sth->fetchrow_hashref ){     push @output, $row;     # print $row->{image};     $photo = $row->{image};     $file = "$photo";     $document = {         local $/ = undef;         open $fh, "<", $file           or die "could not open $file: $!";         <$fh>;     };      $encoded= mime::base64::encode_base64($document); } 

with json looking this:

{"mydata":[{"favorited":null,"date":"2013-07-31","preferredmeetinglocation":"meet here","description":"clothes desc","image":"/var/www/pictures/photo-7h1sisxq.jpg","id":"31","title":"clothing ","price":"12","category":"clothing","isbn":null}]} 

and want in place of shows file path image want change actual image each object in json string. want encode each image base64 know how part. need changing /var/www/pictures/photo-7h1sisxq.jpg in case can work , encode.

as daxim correctly said, want substitute image data before encode data structure json. want use mime::base64 encoding. result similar to:

use mime::base64 qw(encode_base64); use file::slurp;  $base64_encoded_image =  encode_base64 scalar read_file($filename, binmode => ':raw'); 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -