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@issel.ee.auth.gr Site : http://fotis.ee.auth.gr
On 07/30/2013 06:27 PM, Fotis E. Psomopoulos wrote:
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?
Why don't you use the functions of the upload object to store the uploaded file? Also you open the file for reading, not for writing. Regards Racke -- LinuXia Systems => http://www.linuxia.de/ Expert Interchange Consulting and System Administration ICDEVGROUP => http://www.icdevgroup.org/ Interchange Development Team
Dear Racke, thank you for your response.
On 07/30/2013 06:27 PM, Fotis E. Psomopoulos wrote:
/ 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 testhttp://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? />/> /> Why don't you use the functions of the upload object to store the uploaded file?
I have tried the following code: put '/upload/:file' => sub { my $upload_dir = "c:/Fotis/INA-CERTH/Microme/PathTrace/WebApp/PathTraceWS/UPLOADS"; my $filename = params->{file}; my $uploadedFile = request->upload($filename); $uploadedFile->copy_to('$upload_dir'); debug "My Log 1: " . params->{file}; debug "My Log 2: " . ref($uploadedFile); return "DONE"; }; However, the problem is probably the same as before: / //request to PUT /upload/test crashed: Can't call method "copy_to" on an undefined value/ What I really cannot understand is why the second debug line returns empty (...ref($uploadedFile)...).
Also you open the file for reading, not for writing.
Well that's embarrassing... However, I corrected it and the problem remains (for some reason, it doesn't get the file). Thank you very much for your time! Regards, Fotis
On Tue, Jul 30, 2013, at 10:27, Fotis E. Psomopoulos wrote:
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);
Are you sure you don't mean my ($uploadedFile) = request->upload('file'); (because the uploads are keyed by the parameter name, not the filename - but I could be wrong, I'm not very familiar with Dancer, myself.)
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
-- Curtis Jewell csjewell@cpan.org http://csjewell.dreamwidth.org/ perl@csjewell.fastmail.us http://csjewell.comyr.org/perl/ "Your random numbers are not that random" -- perl-5.10.1.tar.gz/util.c Strawberry Perl for Windows betas: http://strawberryperl.com/beta/
Hi, I think I found out what the problem was (PUT vs POST error). This is the new (working) code: post '/upload/:file' => sub { my $upload_dir = "MyApp/UPLOADS"; my $filename = params->{file}; my $uploadedFile = upload('file_input_foo'); $uploadedFile->copy_to("$upload_dir/$filename"); }; Thank you all for your time and responses! Regards, Fotis On 30/7/2013 8:25 μμ, Curtis Jewell wrote:
On Tue, Jul 30, 2013, at 10:27, Fotis E. Psomopoulos wrote:
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); Are you sure you don't mean
my ($uploadedFile) = request->upload('file');
(because the uploads are keyed by the parameter name, not the filename - but I could be wrong, I'm not very familiar with Dancer, myself.)
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
-- Curtis Jewell csjewell@cpan.org http://csjewell.dreamwidth.org/ perl@csjewell.fastmail.us http://csjewell.comyr.org/perl/
"Your random numbers are not that random" -- perl-5.10.1.tar.gz/util.c
Strawberry Perl for Windows betas: http://strawberryperl.com/beta/
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-- 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@issel.ee.auth.gr Site : http://fotis.ee.auth.gr
If you want to use that in a web form, you have to go with the POST solution. 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). Ciao, Flavio. On Thu, Aug 1, 2013 at 9:38 AM, Fotis E. Psomopoulos <fpsom@issel.ee.auth.gr
wrote:
Hi,
I think I found out what the problem was (PUT vs POST error). This is the new (working) code:
post '/upload/:file' => sub {
my $upload_dir = "MyApp/UPLOADS"; my $filename = params->{file}; my $uploadedFile = upload('file_input_foo'); $uploadedFile->copy_to("$**upload_dir/$filename"); };
Thank you all for your time and responses!
Regards,
Fotis
On 30/7/2013 8:25 μμ, Curtis Jewell wrote:
On Tue, Jul 30, 2013, at 10:27, Fotis E. Psomopoulos wrote:
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);
Are you sure you don't mean
my ($uploadedFile) = request->upload('file');
(because the uploads are keyed by the parameter name, not the filename - but I could be wrong, I'm not very familiar with Dancer, myself.)
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<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
-- Curtis Jewell csjewell@cpan.org http://csjewell.dreamwidth.**org/<http://csjewell.dreamwidth.org/> perl@csjewell.fastmail.us http://csjewell.comyr.org/**perl/<http://csjewell.comyr.org/perl/>
"Your random numbers are not that random" -- perl-5.10.1.tar.gz/util.c
Strawberry Perl for Windows betas: http://strawberryperl.com/**beta/<http://strawberryperl.com/beta/>
______________________________**_________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/**mailman/listinfo/dancer-users<http://lists.preshweb.co.uk/mailman/listinfo/dancer-users>
-- 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@issel.ee.auth.gr Site : http://fotis.ee.auth.gr
______________________________**_________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/**mailman/listinfo/dancer-users<http://lists.preshweb.co.uk/mailman/listinfo/dancer-users>
participants (4)
-
Curtis Jewell -
Flavio Poletti -
Fotis E. Psomopoulos -
Stefan Hornburg (Racke)