Reputation: 163
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!
Upvotes: 0
Views: 906
Reputation: 35198
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?
Upvotes: 1