Downloading a TIF file using LWP?

Downloading a TIF file using LWP?

am 04.09.2006 06:07:55 von nospam

Hello.

I am trying to download a TIFF file using the HTTP protocol.
I am using LWP and the following code snippet. Obviously I am
doing something wrong, since the resulting file will not open
in my viewer, and it is approximately 1/2 the size of the same
file if I open it in my browser and save it (double-byte
character probem, perhaps?)

Any suggestions?

Thanks
-Mark


#!/usr/bin/perl
#
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");

# Create a request
my $req = HTTP::Request->new(GET =>
'http://www.some_domain.com/some_tiff_file.tif');
$req->content_type('image/tiff');

my $res = $ua->request($req);

if ($res->is_success) {
my $OUTFIL;
open ($OUTFIL, ">test.dat") || die $!;
print $OUTFIL $res->content;
close $OUTFIL;
}
else {
print $res->status_line, "\n";
}

Re: Downloading a TIF file using LWP?

am 04.09.2006 07:51:30 von John Bokma

"Mark G." wrote:

> Hello.
>
> I am trying to download a TIFF file using the HTTP protocol.
> I am using LWP and the following code snippet. Obviously I am
> doing something wrong, since the resulting file will not open
> in my viewer, and it is approximately 1/2 the size of the same
> file if I open it in my browser and save it (double-byte
> character probem, perhaps?)
>
> Any suggestions?
>
> Thanks
> -Mark
>
>
> #!/usr/bin/perl
> #

use strict;
use warnings;


> use LWP::UserAgent;
> $ua = LWP::UserAgent->new;
> $ua->agent("MyApp/0.1 ");
>
> # Create a request
> my $req = HTTP::Request->new(GET =>
> 'http://www.some_domain.com/some_tiff_file.tif');

use example.com for examples

> $req->content_type('image/tiff');


my $url = .... # as above
my $response = $ua->get( $url, :content_file => 'test.tiff' );
$response->is_success or die $response->status_line;

No idea if this fix the issue though, but it makes your code shorter :-D.

--
John Experienced Perl programmer: http://castleamber.com/

Perl help, tutorials, and examples: http://johnbokma.com/perl/

Re: Downloading a TIF file using LWP?

am 04.09.2006 10:51:53 von Sisyphus

"Mark G." wrote in message
..
..
> if ($res->is_success) {
> my $OUTFIL;
> open ($OUTFIL, ">test.dat") || die $!;

binmode($OUTFIL);

> print $OUTFIL $res->content;
> close $OUTFIL;
> }
> else {
> print $res->status_line, "\n";
> }
>

Seems odd to be calling a tif file "test.dat". Perhaps I've misunderstood
something.

Cheers,
Rob

Re: Downloading a TIF file using LWP?

am 04.09.2006 18:53:16 von nospam

"Mark G." wrote:
>
> Any suggestions?

And the problem was. . ."coding while drowsy."

After a good night's sleep, I switched the output file handle to binary
mode:

binmode $OUTFIL;

And all was well.

Thanks to all who responded.

-Mark