yourkeylady
Programmer
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.
Thanks
Tricia
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