use strict; use warnings; use util_routines; use DBI; my $my_picture_file = "c:\\users\\xxx\\work\\blob.jpg"; my $dbname = "a.dat"; my $dbh = util_routines::connect_to_sqlite($dbname); create_my_blob(); open (my $MYFILE,'<', $my_picture_file) or die "Cannot open file....$!"; my $data; { local $/; $data = <$MYFILE>; close $MYFILE; } $data =~ s/^\s+//g; $data =~ s/\s+$//g; # insert image into table my $sql = "INSERT INTO my_blob VALUES (?)"; my $sth = $dbh->prepare($sql) or die; $sth->execute($data) or die; # retrieve image from table $sql = "SELECT image FROM my_blob"; $sth = $dbh->prepare($sql) or die; $sth->execute() or die; my $ref = $sth->fetchrow_hashref; my $newdata = $$ref{'image'}; $newdata =~ s/^\s+//g; $newdata =~ s/\s+$//g; open (my $OUTPUT, '>', "output_blob.jpg") or die "$!\n"; print $OUTPUT $newdata; close $OUTPUT; $sth->finish; $dbh->disconnect; sub create_my_blob { $dbh->do('drop table my_blob'); my $sql = qq/create table my_blob (image blob)/; $dbh->do($sql) or die "\n\n$DBI::errstr"; print "Created my_blob\n"; return; } __END__