FAQ
Hi,

I have a form that contains a File element whose binary content should be uploaded in my database. The corresponding column in the db is of type BLOB.

Right now my "create" action looks like this:

(...)
if ($form->submitted_and_valid) {
my $cover = $c->request->upload('cover');
my $inhalt = $cover->slurp;
$c->model('DB::Medien')->create({
typ => $form->param_value('typ'),
titel => $form->param_value('titel'),
titel2 => $form->param_value('titel2'),
erscheinungsjahr => $form->param_value('erscheinungsjahr'),
bewertung => $form->param_value('bewertung'),
cover => $inhalt,
mime => $cover->type,
});
(...)

This works, but obviously is not quite elegant or scalable as other "create" actions in my catalyst application look like this:

(...)
if ($form->submitted_and_valid) {
my $benutzer = $c->model('DB::Benutzer')->new_result({});
$form->model->update($benutzer);
(...)

The reason I chose the first version ("->create" instead of "->new_result"): I do not know how to get the File element working with the second version. I tried (unsuccessfully) this:

(...)
if ($form->submitted_and_valid) {
my $cover = $c->request->upload('cover');
my $inhalt = $cover->slurp;
my $medium = $c->model('DB::Medien')->new_result({});
$medium->cover($inhalt);
$medium->mime($cover->type);
$form->model->update($medium);
(...)

Any idea on how to get this right?
Thanks

J?rgen
--
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser

Search Discussions

  • Moritz Onken at Jan 4, 2010 at 11:19 am

    (...)
    if ($form->submitted_and_valid) {
    my $cover = $c->request->upload('cover');
    my $inhalt = $cover->slurp;
    my $medium = $c->model('DB::Medien')->new_result({});
    $medium->cover($inhalt);
    $medium->mime($cover->type);
    $form->model->update($medium);
    (...)

    Any idea on how to get this right?
    Thanks
    I'd try

    (...)
    if ($form->submitted_and_valid) {
    my $cover = $c->request->upload('cover');
    my $inhalt = $cover->slurp;
    my $medium = $c->model('DB::Medien')->new_result({});
    $form->model->update($medium);
    $medium->cover($inhalt);
    $medium->mime($cover->type);
    $medium->update;
    (...)


    This adds an extra update query but shouldn't be a deal breaker.

    cheers,

    moritz

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouphtml-formfu @
categoriesperl, catalyst
postedJan 4, '10 at 7:41a
activeJan 4, '10 at 11:19a
posts2
users2
websitemetacpan.org...

2 users in discussion

Moritz Onken: 1 post Jürgen Hensch: 1 post

People

Translate

site design / logo © 2022 Grokbase