I'm a newbie to Mojolicious, thank you for the example, it helped me
understand how to upload multiple files.
I tried the example, only get the name of the last file.
Checked the latest documents of Mojolicious, $self->req->upload('files')
only returns the last one per https://metacpan.org/pod/Mojo::Message#upload,
Tried the methods https://metacpan.org/pod/Mojo::Message#uploads, it works.
my @files;
my $files_ref = $self->req->uploads('files');
for my $file ( @$files_ref ) {
my $size = $file->size;
my $name = $file->filename;
push @files, "$name ($size)";
}
On Sunday, October 27, 2013 at 4:57:55 PM UTC+8, Andrey Khozov wrote:
>
> Hi.
>
> To access files from form in the controller, you should use the method
> http://mojolicio.us/perldoc/Mojo/Message#upload
> <http://www.google.com/url?q=http%3A%2F%2Fmojolicio.us%2Fperldoc%2FMojo%2FMessage%23upload&sa=D&sntz=1&usg=AFQjCNFv2VXTWWj8jgvuIE0cxeRq06ENCQ>.
>
> A simple example:
>
> #!/usr/bin/perl -w
>
> use Mojolicious::Lite;
>
> get '/' => 'page';
> post '/' => sub {
> my $self = shift;
> my @files;
> for my $file ($self->req->upload('files')) {
> my $size = $file->size;
> my $name = $file->filename;
> push @files, "$name ($size)";
> }
> $self->render(text => "@files");
> } => 'save';
>
> app->start;
>
> __DATA__
>
> @@ page.html.ep
> <!DOCTYPE html>
> <html>
> <body>
> <form action="<%= url_for 'save' %>" method="POST"
> enctype="multipart/form-data">
> <input name="files" type="file" multiple="multiple">
> <button type="submit">Upload</button>
> </form>
> </body>
> </html>
>
> --
> Andrey Khozov
>
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.