How do you insert binary data into a BLOB column with Class::DBI?

1.5k Views Asked by At

I want to create a new object using Class::DBI. One of the fields of this object is a BLOB type. I have a filehandle I want to use for this data, but apparently, just doing this doesn't work:

my $item = My::Class::DBI::Class->insert({
        foo       => $bar,
        biz       => $baz,
        blob         => $my_filehandle
        });

Is there some trick I am missing?

Thanks!

1

There are 1 best solutions below

0
Leon Timmermans On BEST ANSWER

You have to read out the filehandle, and insert that.

my $blob = do {local $/; <$my_filehandle>};
my $item = My::Class::DBI::Class->insert({
        foo       => $bar,
        biz       => $baz,
        blob         => $blob,
        });