Upload File -> Help

269 views
Skip to first unread message

Renato Forti

unread,
Nov 6, 2012, 5:14:40 AM11/6/12
to mojol...@googlegroups.com
Hi All,

I'm trying upload a file, but my file data is not 'moved' to dir! The file is created, but with 0kb. See my code! I am using normal app (no Lite App)!

First in :

sub startup {
  # ...
  $r->post('/upload')->to('services#upload');
  # ...
}

Now, in Services.pm

sub upload
{
   my $self = shift;

   # Check file size
   return $self->render(text => 'File is too big.', status => 200)
     if $self->req->is_limit_exceeded;

   # Process uploaded file
   my $file = $self->param('_file');
   my $upload = Mojo::Upload->new;

   $upload->move_to('/hades/temp/zones/sa/east/1b/temp/foo.txt');
     
   my $size = $upload->size;
   my $name = $upload->filename;

   $self->render(text => "Thanks for uploading $size byte file $name.");
}
What is wrong!!!?

Anoter question: How do I can put a loadding bar on File Updload Web Page! Any Idea? 

Thanks

Ben van Staveren

unread,
Nov 6, 2012, 5:20:18 AM11/6/12
to mojol...@googlegroups.com
Try using:

my $upload = $self->req->upload('_file');


On 11/06/2012 05:14 PM, Renato Forti wrote:
> Hi All,
>
> I'm trying upload a file, but my file data is not 'moved' to dir! The file
> is created, but with 0kb. See my code! I am using normal app (no Lite App)!
>
> First in :
>
> sub startup {
> # ...
> $r->post('/upload')->to('services#upload');
> # ...
> }
>
> Now, in Services.pm
>
> sub upload
> {
> my $self= shift;
>
> # Check file size
> return $self->render(text=> 'File is too big.', status=> 200)
> if $self->req->is_limit_exceeded;
>
> # Process uploaded file
> my $file= $self->param('_file');
> my $upload= Mojo::Upload->new;
>
> $upload->move_to('/hades/temp/zones/sa/east/1b/temp/foo.txt');
>
> my $size= $upload->size;
> my $name= $upload->filename;
>
> $self->render(text=> "Thanks for uploading $size byte file $name.");
> }
>
> What is wrong!!!?
>
> Anoter question: How do I can put a loadding bar on File Updload Web Page! Any Idea?
>
> Thanks
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mojolicious/-/h2hxPjHnNJAJ.
> To post to this group, send email to mojol...@googlegroups.com.
> To unsubscribe from this group, send email to
> mojolicious...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mojolicious?hl=en.

--
Ben van Staveren
phone: +62 81 70777529
email: benvans...@gmail.com

Renato Forti

unread,
Nov 6, 2012, 6:34:15 AM11/6/12
to mojol...@googlegroups.com
Hi Thanks for help!

It works!!! :o)

lenz

unread,
Nov 6, 2012, 6:14:47 PM11/6/12
to mojol...@googlegroups.com
i wrote a uploader the other day, have a look here:

https://github.com/norbu09/planet-express-ship/commit/d033319d5b139baa7aafe372062e78a3f1d48269

it uses a quite nice uploader frontend that supports html5 and flash
uploads as well as normal posts.

cheers
lenz
> https://groups.google.com/d/msg/mojolicious/-/awLXOXkk5J0J.

Renato Forti

unread,
Nov 7, 2012, 5:48:06 AM11/7/12
to mojol...@googlegroups.com
Tks!!!
Reply all
Reply to author
Forward
0 new messages