[dancer-users] Trouble in uploading file

Fotis E. Psomopoulos fpsom at issel.ee.auth.gr
Tue Jul 30 17:27:03 BST 2013


Dear all,

I am quite new to Dancer but I am really amazed on how few lines of code 
I have to write for the same functionality (still exploring though).

However, I have hit the following issue: I am trying to upload a file 
using the following code:

put '/upload/:file' =>  sub {
     my $upload_dir = "MyApp/UPLOADS";
     my $filename = params->{file};
     my $uploadedFile = request->upload($filename);

     debug "My Log 1: " . params->{file};
     debug "My Log 2: " . ref($uploadedFile);

     open ( UPLOADFILE, "$upload_dir/$filename" ) or die "$!";

     while ( <UPLOADFILE> )
     {
         print UPLOADFILE;
     }

     close UPLOADFILE;

     return "DONE";
};

The PUT command is done via cURL as follows:

curl --upload-file test http://localhost:3000/upload/test
DONE

The output that I see in the "development dance floor" is the following:

[9072]  core @0.000341> request: PUT /upload/test from 127.0.0.1 in 
/Perl/site/lib/Dancer/Handler.pm l. 56
[9072]  core @0.002434> [hit #1]Trying to match 'PUT /upload/test' 
against /^\/upload\/([^\/]+)$/ (generated from '/upload/:file') in 
/Perl/site/lib/Dancer/Route.pm l. 84
[9072]  core @0.004173> [hit #1]  --> got 1 in 
/Perl/site/lib/Dancer/Route.pm l. 102
[9072]  core @0.006625> [hit #1]  --> named tokens are: file in 
/Perl/site/lib/Dancer/Route.pm l. 130
[9072] debug @0.009443> [hit #1]My Log 1: test in MyApp\lib/MyApp.pm l. 20
[9072] debug @0.010818> [hit #1]*My Log 2:  in MyApp\lib/MyApp.pm l. 21*
[9072]  core @0.015854> [hit #1]response: 200 in 
/Perl/site/lib/Dancer/Handler.pm l. 179

The problem is that the file is created with the correct name in the 
correct folder (MyApp/UPLOADS/test) but it is always empty (0 size). No 
other warnings or errors, but I do see an issue in the output (marked in 
bold - 2nd custom debug line). Any ideas?

Thank you in advance for your time!

Regards,

Fotis

-- 
Fotis E. Psomopoulos
PhD, Software Engineer
Intelligent Systems and Software Engineering Lab
Department of Electrical and Computer Engineering
Aristotle University of Thessaloniki
Thessaloniki 54124, Greece

Phone: +30 2310 99 6349
Fax  : +30 2310 99 6398
Email: fpsom at issel.ee.auth.gr
Site : http://fotis.ee.auth.gr

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20130730/05e9a2f8/attachment.htm>


More information about the dancer-users mailing list