Mojolicious Lite文件上传

时间:2014-07-14 19:29:30

标签: perl upload mojolicious-lite

我无法弄清楚如何在Mojolicious Lite中将文件上传到远程服务器。这里有一些代码,首先是html格式:

<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>

这是一个add_photo测试路线:

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');
};

这是我收到的错误消息:

  

找不到对象方法&#34; filename&#34;通过包&#34; name_of_file.jpg&#34; (也许你忘了在sv第31行加载&#34; name_of_file.jpg&#34;?)

提前致谢!

1 个答案:

答案 0 :(得分:1)

编码类型位于表单标记中,而不是文件输入:

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

有关详细示例,请查看:Mojolicious::Lite #File uploads

此外,这个问题/答案也有类似的信息:How Upload file using Mojolicious?