Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

write to .jpg error problem

by traincity (Sexton)
on Jul 01, 2019 at 20:49 UTC ( [id://11102271]=perlquestion: print w/replies, xml ) Need Help??

traincity has asked for the wisdom of the Perl Monks concerning the following question:

I am getting this error message which seems to be preventing most of a particular page to be written:

Mon Jul 01 16:26:46.898774 2019 cgi:error pid 6060:tid 1144 client ::1:58540 AH01215: Can't write to 'localhost/choo/tcimages/176801_1.JPG-14660': No such file or directory at C:/Strawberry/perl/vendor/lib/LWP/Protocol.pm line 114. at C:/Strawberry/perl/vendor/lib/LWP/UserAgent.pm line 982.\r: C:/Apache24/htdocs/choo/cgi-bin/ua/main.pl

I found protocol.pm but have no idea how to deal with this. As far as I can tell line 114 is the die statement:

This can't be moved to Try::Tiny due to the closures within causing # leaks on any version of Perl prior to 5.18. # https://perl5.git.perl.org/perl.git/commitdiff/a0d2bbd5c my $error = do { #catch local $@; local $\; # protect the print below from surprises eval { # try if (!defined($arg) || !$response->is_success) { $response->{default_add_content} = 1; } elsif (!ref($arg) && length($arg)) { open(my $fh, ">", $arg) or die "Can't write to '$arg': + $!"; binmode($fh); push(@{$response->{handlers}{response_data}}, { callback => sub { print $fh $_[3] or die "Can't write to '$arg': + $!"; 1;

I have no idea what to do here. I hope I presented this so it makes some sense to someone.

Thanks for any help.

Replies are listed 'Best First'.
Re: write to .jpg error problem
by haukex (Archbishop) on Jul 01, 2019 at 21:27 UTC
    Can't write to 'localhost/choo/tcimages/176801_1.JPG-14660': No such file or directory ... I have no idea what to do here.

    Have you checked if there's a directory like that?

    Since the pathname is relative, it's relative to whatever the current working directory is when that open executes. Because the working directory can change, normally absolute pathnames are better; if there's a configuration option somewhere that sets the path for these files, you might want to check that it's set to an absolute path rather than a relative one.

    As for the code, note the filename is being passed in as $arg, so this particular code doesn't help, you'd have to trace back where $arg is coming from.

      Thanks very much. I now understand. In the administration file I changed to this:

      $config{'image_upload_dir'}   = 'c:/apache24/htdocs/choo/tcimages';

        One step forward, but another change you wouldn't have had to make had you gone down VM route suggested earlier.

Re: write to .jpg error problem
by Corion (Patriarch) on Jul 01, 2019 at 21:29 UTC

    Most likely, parts (or all) of the directories localhost/choo/tcimages/ are missing.

    As you don't show your code which causes the error, it's hard to suggest a solution, but most likely, either creating the directories localhost and localhost/choo and localhost/choo/tcimages will make it possible to save files there.

Re: write to .jpg error problem
by bliako (Monsignor) on Jul 01, 2019 at 23:30 UTC

    This can help you find out where you are (cwd) and what file you are trying to open and whether destination's folder is valid like others have suggested:

    use Cwd; print "Now at dir: '".cwd()."' and arg is '$arg'.\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11102271]
Approved by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-24 06:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found