Hi folks - I'd be grateful for some help with someone experienced using Catalyst::Request::Upload.

The problem: I'm trying to integrate the Aurigma file-uploader, which sends files to the server using normal HTTP form-upload stuff.

On the server-side, I want to use $upload->copt_to() to get the file. But it's not working.

The OS error message is 'No such file or directory'.

It turns out that this is fair enough because when I check $upload->tempname, it's empty. But the file itself does actually appear in the tmp directory.

debug output shows that $request->uploads looks like this:

uploads => { SourceFile_1 => bless({ "/tmp/5xSW7Swasp" => "filename", "HTTP::Headers=HASH(0x40f1470)" => "temp +name", "aaa.jpg" => undef, "charset=utf-8; Content-Transfer-Encodin +g: binary" => "headers", size => 374205, type => "image/jpeg", }, "Catalyst::Request::Upload"), },

As you can see, it looks like some of the keys and values in the C:R:U hash have been swapped with one another! which I'm guessing could well have something to do with the cause of the problem. I.e. the blessed hash has no 'filename' key because 'filename' is actually there as a value, with the literal filename itself as the key!

argh!

My code is this:

#Get source file and save it to disk. my $sourceFilePath = $c->req->param("FileName_" . $i); my $fileName = $absGalleryPath . get_safe_file_name($sourceFi +lePath); $c->log->warn('new filename is '.$fileName); $c->log->warn('upload object is: '.$c->req->uploads->{"SourceF +ile_" . $i}); my $result; $result = $c->req->uploads->{"SourceFile_" . $i}->copy_to($fil +eName) or $c->error("no copy.\nfrom:".$c->req->uploads->{"SourceF +ile_" . $i}->tempname."\nto:$fileName \nsyserr: $!");

and this is the corresponding console output from the server:

[info] *** Request 5 (0.079/s) [1115] [Fri Mar 26 14:04:22 2010] *** [debug] File Uploads are: .--------------+----------------------------+--------------------+---- +-------. | Parameter | Filename | Type | Siz +e | +--------------+----------------------------+--------------------+---- +-------+ | SourceFile_1 | | image/jpeg | 374 +205 | '--------------+----------------------------+--------------------+---- +-------' [debug] Body Parameters are: .-------------------------------------+------------------------------- +-------. | Parameter | Value + | +-------------------------------------+------------------------------- +-------+ | Angle_1 | 0 + | | Description_1 | + | | FileCount | 1 + | | FileName_1 | aaa.jpg + | | Height_1 | 800 + | | HorizontalResolution_1 | 72 + | | PackageCount | -1 + | | PackageGuid | {7CEEC530-48D4-4499-A23B-79BA5 +9731F- | | | 98} + | | PackageIndex | 0 + | | SourceFileCreatedDateTimeLocal_1 | 2010:03:18 15:11:32 + | | SourceFileCreatedDateTime_1 | 2010:03:18 15:11:32 + | | SourceFileLastModifiedDateTimeLoca- | 2010:03:18 15:11:32 + | | l_1 | + | | SourceFileLastModifiedDateTime_1 | 2010:03:18 15:11:32 + | | SourceFileSize_1 | 374205 + | | VerticalResolution_1 | 72 + | | Width_1 | 800 + | '-------------------------------------+------------------------------- +-------' [debug] "POST" request for "upload_photos" from "192.168.1.105" [debug] Path is "upload_photos" [warn] new filename is /Users/andye/PhotoApp/root/static/Gallery/aaa.j +pg [warn] upload object is: Catalyst::Request::Upload=HASH(0x40f14d0) [error] no copy. from: to:/Users/andye/PhotoApp/root/static/Gallery/aaa.jpg syserr: No such file or directory [info] Request took 1.327533s (0.753/s) .------------------------------------------------------------+-------- +---. | Action | Time + | +------------------------------------------------------------+-------- +---+ | /upload_photos | 0.00240 +3s | | /end | 0.00042 +8s | '------------------------------------------------------------+-------- +---'

er, help? ;)

Many thanks.


In reply to Catalyst::Request::Upload inside-out-object weirdness by andye

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.