Re: Problems writing binary uploaded data...
I've (Or rather Issac, on the list) sorted it out - I simply forgot to close the file after writing it... pretty silly :) cheers Snorre On Wed, 23 Oct 2002 [EMAIL PROTECTED] wrote: Hmm, I've tried your code on my system and it does exactly what it's supposed to. I get the same filesizes reported at the destination end and in the script as the file is on my PC HDD. Have you tried a different file ? Do you always loose the same amount ? Cheers Paul *** Important. Confidentiality: This communication is intended for the above-named person and may be confidential and/or legally privileged. Any opinions expressed in this communication are not necessarily those of the company. If it has come to you in error you must take no action based on it, nor must you copy or show it to anyone; please delete/destroy and inform the sender immediately. Monitoring/Viruses Orange may monitor all incoming and outgoing emails in line with current legislation. Although we have taken steps to ensure that this email and attachments are free from any virus, we advise that in keeping with good computing practice the recipient should ensure they are actually virus free. Orange PCS Limited is a subsidiary of Orange SA and is registered in England No 2178917, with its address at St James Court, Great Park Road, Almondsbury Park, Bradley Stoke, Bristol BS32 4QJ. ***
Re: Problems writing binary uploaded data...
Well, there are 2 issues here: 1) Getting $upload-link to work (yes, you can do it if you really want to:-)) 2) Fixing your original problem So: 1) Use TEMP_DIR to set a different spool directory for the uploaded file: From the same manpage: (under methods to pass $apr-new()) TEMP_DIR Sets the directory where upload files are spooled. On a *nix-like that supports link(2), the TEMP_DIR should be located on the same file system as the final destination file: my $apr = Apache::Request-new($r, TEMP_DIR = /home/httpd/tmp); my $upload = $apr-upload('file'); $upload-link(/home/user/myfile) || warn link failed: $!; 2) I'm not really sure - I only gave your problem a rather casual look-over, but my first instinct is to add close (OUTFILE); to the end of your code - perhaps it's not flushing the output buffer to the file since you never explicitly close the filehandle... Issac - Original Message - From: Leif Snorre Schøyen Boasson [EMAIL PROTECTED] To: Issac Goldstand [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, October 22, 2002 8:51 PM Subject: Re: Problems writing binary uploaded data... Well, the original reason I didn't use that was I didn't know what linking it was used for... (so much for RTFM... :) ). However, my /tmp (which Apache is using as it's tmp-directory) is on its own partition, so I cant really link it anywhere else but /tmp, which is not exactly where I'd like it to go... Is there any other way to get it saved directly like that, and not having to cp it somewhere else? (and I'd still like to know why my original code doesn't work... :) ) Thanks alot for the advice, though! cheers Snorre On Tue, 22 Oct 2002, Issac Goldstand wrote: Um... Why don't you simply use $upload-link on the handle? From Apache::Request manpage my $upload = $apr-upload('file'); $upload-link(/path/to/newfile) or die sprintf link from '%s' failed: $!, $upload-tempname; /From Apache::Request manpage Issac - Original Message - From: Leif Snorre Schøyen Boasson [EMAIL PROTECTED] To: mod_perl [EMAIL PROTECTED] Sent: Tuesday, October 22, 2002 6:08 PM Subject: Problems writing binary uploaded data... I'm trying to save an uploaded binary file (a jpg) through a perlscript. The code doing this looks like: if (open OUTFILE, /var/www/tmp/test.jpg){ binmode $ULFILE, :raw; binmode OUTFILE, :raw; while ($sizeread=read($ULFILE, $buffer, 1024)) { print OUTFILE $buffer; $size += $sizeread; } print brRead ,$size, bytes.; } Where ULFILE is the filehandle for the uploaded file, gotten from an Apache::Request object. Now, the sum of the sizes reported by the read-command is correct for the original jpg file I use to test, but the written file is somewhat smaller (7192 bytes smaller), so I figure something gets lost in the writing. But I cant figure out how or why... ...anybody see some reason why I shouldnt get the exact binary data out?
Re: Problems writing binary uploaded data...
Um... Why don't you simply use $upload-link on the handle? From Apache::Request manpage my $upload = $apr-upload('file'); $upload-link(/path/to/newfile) or die sprintf link from '%s' failed: $!, $upload-tempname; /From Apache::Request manpage Issac - Original Message - From: Leif Snorre Schøyen Boasson [EMAIL PROTECTED] To: mod_perl [EMAIL PROTECTED] Sent: Tuesday, October 22, 2002 6:08 PM Subject: Problems writing binary uploaded data... I'm trying to save an uploaded binary file (a jpg) through a perlscript. The code doing this looks like: if (open OUTFILE, /var/www/tmp/test.jpg){ binmode $ULFILE, :raw; binmode OUTFILE, :raw; while ($sizeread=read($ULFILE, $buffer, 1024)) { print OUTFILE $buffer; $size += $sizeread; } print brRead ,$size, bytes.; } Where ULFILE is the filehandle for the uploaded file, gotten from an Apache::Request object. Now, the sum of the sizes reported by the read-command is correct for the original jpg file I use to test, but the written file is somewhat smaller (7192 bytes smaller), so I figure something gets lost in the writing. But I cant figure out how or why... ...anybody see some reason why I shouldnt get the exact binary data out?
Re: Problems writing binary uploaded data...
Hmm, I've tried your code on my system and it does exactly what it's supposed to. I get the same filesizes reported at the destination end and in the script as the file is on my PC HDD. Have you tried a different file ? Do you always loose the same amount ? Cheers Paul *** Important. Confidentiality: This communication is intended for the above-named person and may be confidential and/or legally privileged. Any opinions expressed in this communication are not necessarily those of the company. If it has come to you in error you must take no action based on it, nor must you copy or show it to anyone; please delete/destroy and inform the sender immediately. Monitoring/Viruses Orange may monitor all incoming and outgoing emails in line with current legislation. Although we have taken steps to ensure that this email and attachments are free from any virus, we advise that in keeping with good computing practice the recipient should ensure they are actually virus free. Orange PCS Limited is a subsidiary of Orange SA and is registered in England No 2178917, with its address at St James Court, Great Park Road, Almondsbury Park, Bradley Stoke, Bristol BS32 4QJ. ***
Problems writing binary uploaded data...
I'm trying to save an uploaded binary file (a jpg) through a perlscript. The code doing this looks like: if (open OUTFILE, /var/www/tmp/test.jpg){ binmode $ULFILE, :raw; binmode OUTFILE, :raw; while ($sizeread=read($ULFILE, $buffer, 1024)) { print OUTFILE $buffer; $size += $sizeread; } print brRead ,$size, bytes.; } Where ULFILE is the filehandle for the uploaded file, gotten from an Apache::Request object. Now, the sum of the sizes reported by the read-command is correct for the original jpg file I use to test, but the written file is somewhat smaller (7192 bytes smaller), so I figure something gets lost in the writing. But I cant figure out how or why... ...anybody see some reason why I shouldnt get the exact binary data out?
Re: Problems writing binary uploaded data...
Well, the original reason I didn't use that was I didn't know what linking it was used for... (so much for RTFM... :) ). However, my /tmp (which Apache is using as it's tmp-directory) is on its own partition, so I cant really link it anywhere else but /tmp, which is not exactly where I'd like it to go... Is there any other way to get it saved directly like that, and not having to cp it somewhere else? (and I'd still like to know why my original code doesn't work... :) ) Thanks alot for the advice, though! cheers Snorre On Tue, 22 Oct 2002, Issac Goldstand wrote: Um... Why don't you simply use $upload-link on the handle? From Apache::Request manpage my $upload = $apr-upload('file'); $upload-link(/path/to/newfile) or die sprintf link from '%s' failed: $!, $upload-tempname; /From Apache::Request manpage Issac - Original Message - From: Leif Snorre Schøyen Boasson [EMAIL PROTECTED] To: mod_perl [EMAIL PROTECTED] Sent: Tuesday, October 22, 2002 6:08 PM Subject: Problems writing binary uploaded data... I'm trying to save an uploaded binary file (a jpg) through a perlscript. The code doing this looks like: if (open OUTFILE, /var/www/tmp/test.jpg){ binmode $ULFILE, :raw; binmode OUTFILE, :raw; while ($sizeread=read($ULFILE, $buffer, 1024)) { print OUTFILE $buffer; $size += $sizeread; } print brRead ,$size, bytes.; } Where ULFILE is the filehandle for the uploaded file, gotten from an Apache::Request object. Now, the sum of the sizes reported by the read-command is correct for the original jpg file I use to test, but the written file is somewhat smaller (7192 bytes smaller), so I figure something gets lost in the writing. But I cant figure out how or why... ...anybody see some reason why I shouldnt get the exact binary data out?