Hi Sunnavy,

just to give you a short feedback (better late than never ;-) ): You are right, using "request->body()" worked for me.  I simply misinterpreted the documentation thinking  that "upload" would provide access to any uploads. But - as the documentation says - it provides access to POST-Uploads. PUT-Uploads obviously are something different.

Thanks,
Stefan


Am 26.11.2010 13:17, schrieb sunnavy:
Hi Stefan

since you use 'put', I think you just need request->body() to get the content.
upload() is for 'post' only fyi.

best wishes
sunnavy

On 10-11-22 16:53, Stefan Oberwahrenbrock wrote:
Hello!

I have some trouble handling file uploads with my first dancer app. Maybe someone can point me in the right direction:

To get hold of an uploaded file sent via PUT, I have set up this route handler:

put '/upload/:file' => sub {
    my $upload = upload( params->{file} );

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

To test the handler, I  feed it with some data sent by "curl":
curl --upload-file /srv/mydata.tar.gz http://localhost:3000/upload/

As far as I understand the documentation, $upload should hold a reference to an object of typ Dancer::Request::Upload now. Thus, methods like "filename", "basename", "tempname" etc. should be accessible. The logfile looks quite good - at the beginning:
[3432] debug @0.003234> [hit #1] trying to match `/upload/mydata.tar.gz' against /^\/upload\/([^\/]+)$/ in /usr/local/share/perl/5.10.0/Dancer/Route.pm l. 73
[3432] debug @0.003493> [hit #1] My Log 1: mydata.tar.gz in lib/mywebapp.pm l. 26

But the next line indicates, that $upload is not what I expect it to be:
[3432] debug @0.003550> [hit #1] My Log 2:  in lib/mywebapp.pm l. 27

In addition to that, calling one of methods mentioned above (e. g. "$upload->filename()" ), produces a runtime error:
Can't call method filename on an undefined value at...

Probably I have not understood the upload() subroutine correctly - any hint is welcome!

Thanks,
Stefan
-- 
GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit 
gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl
_______________________________________________
Dancer-users mailing list
Dancer-users@perldancer.org
http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
_______________________________________________
Dancer-users mailing list
Dancer-users@perldancer.org
http://www.backup-manager.org/cgi-bin/listinfo/dancer-users