<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<pre style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Dear Racke,
thank you for your response.
> On 07/30/2013 06:27 PM, Fotis E. Psomopoulos wrote:
>><i> Dear all,
</i>>><i>
</i>>><i> 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).
</i>>><i>
</i>>><i> However, I have hit the following issue: I am trying to upload a file using the following code:
</i>>><i>
</i>>><i> put '/upload/:file' => sub {
</i>>><i> my $upload_dir = "MyApp/UPLOADS";
</i>>><i> my $filename = params->{file};
</i>>><i> my $uploadedFile = request->upload($filename);
</i>>><i>
</i>>><i> debug "My Log 1: " . params->{file};
</i>>><i> debug "My Log 2: " . ref($uploadedFile);
</i>>><i>
</i>>><i> open ( UPLOADFILE, "$upload_dir/$filename" ) or die "$!";
</i>>><i>
</i>>><i> while ( <UPLOADFILE> )
</i>>><i> {
</i>>><i> print UPLOADFILE;
</i>>><i> }
</i>>><i>
</i>>><i> close UPLOADFILE;
</i>>><i>
</i>>><i> return "DONE";
</i>>><i> };
</i>>><i>
</i>>><i> The PUT command is done via cURL as follows:
</i>>><i>
</i>>><i> curl --upload-file test <a href="http://localhost:3000/upload/test">http://localhost:3000/upload/test</a>
</i>>><i> DONE
</i>>><i>
</i>>><i> The output that I see in the "development dance floor" is the following:
</i>>><i>
</i>>><i> [9072] core @0.000341> request: PUT /upload/test from 127.0.0.1 in /Perl/site/lib/Dancer/Handler.pm l. 56
</i>>><i> [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
</i>>><i> [9072] core @0.004173> [hit #1] --> got 1 in /Perl/site/lib/Dancer/Route.pm l. 102
</i>>><i> [9072] core @0.006625> [hit #1] --> named tokens are: file in /Perl/site/lib/Dancer/Route.pm l. 130
</i>><i>> [9072] debug @0.009443> [hit #1]My Log 1: test in MyApp\lib/MyApp.pm l. 20
</i>><i>> [9072] debug @0.010818> [hit #1]*My Log 2: in MyApp\lib/MyApp.pm l. 21*
</i>><i>> [9072] core @0.015854> [hit #1]response: 200 in /Perl/site/lib/Dancer/Handler.pm l. 179
</i>><i>>
</i>><i>> 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?
</i>><i>>
</i>>
> 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:
<i>
</i><i>request to PUT /upload/test crashed: Can't call method "copy_to" on an undefined value</i>
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
</pre>
</body>
</html>