Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LWP downloading exe binary files corrupted

Status
Not open for further replies.

yourkeylady

Programmer
Jan 8, 2004
63
US
I need to use this code to download large files and monitor the progress. But any type of binary file I download is corrupted. I want to set the content type, but I'm not sure how to insert the code. Can someone show me where I'm going wrong?

Thanks for looking.

Code:
if(open(UPDATE, ">$base/PBsetup.exe")){
     binmode(UPDATE);
}else{
     exit(0);
}

print LOG qq~\nDownloading $url~;
my $expected_length;
$pkg::percent_done = 0;
# seems like the content type should be set here but I'm not sure how to do it.
$pkg::res = $ua->request(HTTP::Request->new(GET => $url),
sub {
     my($chunk, $res) = @_;
     $pkg::percent_done += length($chunk);
     unless (defined $expected_length) {
          $expected_length = $res->content_length || 0;
     }
     if ($expected_length) {
          print 'end', "\n%d%% - ".100 * $pkg::percent_done / $expected_length ;
	
     }
}

Thanks
Tricia
 
Shouldn't the MIME type already be set by the server?

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top