<div dir="ltr"><div><div><div>If you want to use that in a web form, you have to go with the POST solution.<br><br></div>If you're aiming at realizing an API (RESTful or REST-like), you should understand how the file's data are passed. Most probably, when you use curl you have to fetch the file's data directly from the request body (i.e. the file data *is* the request body).<br>
<br></div>Ciao,<br><br></div> Flavio.<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 1, 2013 at 9:38 AM, Fotis E. Psomopoulos <span dir="ltr"><<a href="mailto:fpsom@issel.ee.auth.gr" target="_blank">fpsom@issel.ee.auth.gr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I think I found out what the problem was (PUT vs POST error). This is the new (working) code:<br>
<br>
post '/upload/:file' => sub {<div class="im"><br>
my $upload_dir = "MyApp/UPLOADS";<br>
my $filename = params->{file};<br></div>
my $uploadedFile = upload('file_input_foo');<br>
$uploadedFile->copy_to("$<u></u>upload_dir/$filename");<br>
};<br>
<br>
Thank you all for your time and responses!<br>
<br>
Regards,<br>
<br>
Fotis<div class="HOEnZb"><div class="h5"><br>
<br>
On 30/7/2013 8:25 μμ, Curtis Jewell wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
On Tue, Jul 30, 2013, at 10:27, Fotis E. Psomopoulos wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dear all,<br>
<br>
I am quite new to Dancer but I am really amazed on how few lines of code<br>
I have to write for the same functionality (still exploring though).<br>
<br>
However, I have hit the following issue: I am trying to upload a file<br>
using the following code:<br>
<br>
put '/upload/:file' => sub {<br>
my $upload_dir = "MyApp/UPLOADS";<br>
my $filename = params->{file};<br>
my $uploadedFile = request->upload($filename);<br>
</blockquote>
Are you sure you don't mean<br>
<br>
my ($uploadedFile) = request->upload('file');<br>
<br>
(because the uploads are keyed by the parameter name, not the filename -<br>
but I could be wrong, I'm not very familiar with Dancer, myself.)<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
debug "My Log 1: " . params->{file};<br>
debug "My Log 2: " . ref($uploadedFile);<br>
<br>
open ( UPLOADFILE, "$upload_dir/$filename" ) or die "$!";<br>
<br>
while ( <UPLOADFILE> )<br>
{<br>
print UPLOADFILE;<br>
}<br>
<br>
close UPLOADFILE;<br>
<br>
return "DONE";<br>
};<br>
<br>
The PUT command is done via cURL as follows:<br>
<br>
curl --upload-file test <a href="http://localhost:3000/upload/test" target="_blank">http://localhost:3000/upload/<u></u>test</a><br>
DONE<br>
<br>
The output that I see in the "development dance floor" is the following:<br>
<br>
[9072] core @0.000341> request: PUT /upload/test from 127.0.0.1 in<br>
/Perl/site/lib/Dancer/Handler.<u></u>pm l. 56<br>
[9072] core @0.002434> [hit #1]Trying to match 'PUT /upload/test'<br>
against /^\/upload\/([^\/]+)$/ (generated from '/upload/:file') in<br>
/Perl/site/lib/Dancer/Route.pm l. 84<br>
[9072] core @0.004173> [hit #1] --> got 1 in<br>
/Perl/site/lib/Dancer/Route.pm l. 102<br>
[9072] core @0.006625> [hit #1] --> named tokens are: file in<br>
/Perl/site/lib/Dancer/Route.pm l. 130<br>
[9072] debug @0.009443> [hit #1]My Log 1: test in MyApp\lib/MyApp.pm l.<br>
20<br>
[9072] debug @0.010818> [hit #1]*My Log 2: in MyApp\lib/MyApp.pm l. 21*<br>
[9072] core @0.015854> [hit #1]response: 200 in<br>
/Perl/site/lib/Dancer/Handler.<u></u>pm l. 179<br>
<br>
The problem is that the file is created with the correct name in the<br>
correct folder (MyApp/UPLOADS/test) but it is always empty (0 size). No<br>
other warnings or errors, but I do see an issue in the output (marked in<br>
bold - 2nd custom debug line). Any ideas?<br>
<br>
Thank you in advance for your time!<br>
<br>
Regards,<br>
<br>
Fotis<br>
</blockquote>
--<br>
Curtis Jewell<br>
<a href="mailto:csjewell@cpan.org" target="_blank">csjewell@cpan.org</a> <a href="http://csjewell.dreamwidth.org/" target="_blank">http://csjewell.dreamwidth.<u></u>org/</a><br>
<a href="mailto:perl@csjewell.fastmail.us" target="_blank">perl@csjewell.fastmail.us</a> <a href="http://csjewell.comyr.org/perl/" target="_blank">http://csjewell.comyr.org/<u></u>perl/</a><br>
<br>
"Your random numbers are not that random" -- perl-5.10.1.tar.gz/util.c<br>
<br>
Strawberry Perl for Windows betas: <a href="http://strawberryperl.com/beta/" target="_blank">http://strawberryperl.com/<u></u>beta/</a><br>
<br>
______________________________<u></u>_________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/<u></u>mailman/listinfo/dancer-users</a><br>
</blockquote>
<br></div></div><div class="im HOEnZb">
-- <br>
Fotis E. Psomopoulos<br>
PhD, Software Engineer<br>
Intelligent Systems and Software Engineering Lab<br>
Department of Electrical and Computer Engineering<br>
Aristotle University of Thessaloniki<br>
Thessaloniki 54124, Greece<br>
<br>
Phone: <a href="tel:%2B30%202310%2099%206349" value="+302310996349" target="_blank">+30 2310 99 6349</a><br>
Fax : <a href="tel:%2B30%202310%2099%206398" value="+302310996398" target="_blank">+30 2310 99 6398</a><br>
Email: <a href="mailto:fpsom@issel.ee.auth.gr" target="_blank">fpsom@issel.ee.auth.gr</a><br>
Site : <a href="http://fotis.ee.auth.gr" target="_blank">http://fotis.ee.auth.gr</a><br>
<br></div><div class="HOEnZb"><div class="h5">
______________________________<u></u>_________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/<u></u>mailman/listinfo/dancer-users</a><br>
</div></div></blockquote></div><br></div>