[html-formfu] using new_result with form that contains File element

"Jürgen Hensch" dschei-eidsch at gmx.de
Mon Jan 4 07:41:10 GMT 2010


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



More information about the HTML-FormFu mailing list