in reply to Adding a JPEG file to database
You could try encoding the JPEG files as something like Base64 and storing them as text in the database. The downside with this approach is that it can add to the size of the data by about 30%. Here is an example:
use MIME::Base64; open my $fh, '<', 'file' or die $!; binmode $fh; my( $bytes, $data ); do { $bytes = read $fh, my $buf, 1000; die $! unless defined $bytes; $data .= $buf; } while $bytes != 0; close $fh; print encode_base64($data, '');
Also, instead of using the read function, you could just slurp the entire file into memory, like this:
open my $fh, '<', 'file' or die $!; binmode $fh; local $/ = undef; print encode_base64(<$fh>, '');
|
|---|