How Upload file using Mojolicious?

后端 未结 3 726
傲寒
傲寒 2021-02-07 19:02

I have been trying out Mojolicious web framework based on perl. And I have try to develop a full application instead of the Lite. The problem I am facing is that I am trying to

相关标签:
3条回答
  • 2021-02-07 19:33

    To process uploading files you should use $c->req->uploads

    post '/' => sub {
       my $c = shift;
       my @files;
       for my $file (@{$c->req->uploads('files')}) {
         my $size = $file->size;
         my $name = $file->filename;
    
         push @files, "$name ($size)";
         $file->move_to("C:\\Program Files\\Apache Software Foundation\\Apache24\\htdocs\\ProcessingFolder\\".$name);
       }
       $c->render(text => "@files");
    } => 'save';
    

    See full code here: https://stackoverflow.com/a/28605563/4632019

    0 讨论(0)
  • 2021-02-07 19:38

    (First, you need some HTML form with method="post" and enctype="multipart/form-data", and a input type="file" with name="upload". Just to be sure.)

    If there were no errors, $fileuploaded would be a Mojo::Upload. Then you could check its size, its headers, you could slurp it or move it, with $fileuploaded->move_to('path/file.ext').

    Taken from a strange example.

    0 讨论(0)
  • 2021-02-07 19:40

    You can use Mojolicious::Plugin::RenderFile

    Mojolicious::Plugin::RenderFile

    0 讨论(0)
提交回复
热议问题