简体   繁体   中英

Mojolicious Lite file upload

I can't figure out how to upload files to the remote server in Mojolicious Lite. Here's some code, first, html form:

<form method='post' action='add_photo'>
    <input type="file" name="upload" enctype="multipart/form-data">
  <button type="submit" class="btn btn-default">Submit</button>
</form>

and here's an add_photo testing route:

post '/add_photo' => sub {

    my $self = shift;
    my %params;
    my $file = $self->param('upload');
    $params{filename} = $file->filename;
    $params{filesize} = $file->size;
    $params{worknamne} = $self->param('name');
    $params{stone} = $self->param('stone');
    $params{cat} = $self->param('cat');
    $self->stash(params => \%params);
    $self->render('test');
};

And here's the error message I recive:

Can't locate object method "filename" via package "name_of_file.jpg" (perhaps you forgot to load "name_of_file.jpg"?) at sv line 31

Thanks in advance!

The encoding type goes in the form tag, not the file input:

<form method="post" action="add_photo" enctype="multipart/form-data">

For a detailed example, just look at: Mojolicious::Lite #File uploads

Also, this question/answer has similar information: How Upload file using Mojolicious?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM