andye has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
---|