You Are Here:

Community: Wiki

This page was last modified on 7 September 2009, at 08:05.

How to show file download progress

From Forum Nokia Wiki

The following article shows how to show the progress of a file being downloaded using the HTTP Client.

Many times we would like to show the amount or the percentage of file that has been downloaded during the transfer. This can be achieved in the MHFRunL function.

Reviewer Approved   

Get the total file size of the file being downloaded

Use the case EGotResponseHeaders for this

RHTTPResponse resp = aTransaction.Response();
RHTTPHeaders headers = resp.GetHeaderCollection();
RStringPool string_pool = iSession.StringPool();
RStringF contLength = string_pool.StringF(HTTP::EContentLength, RHTTPSession::GetTable());
 
THTTPHdrVal tempHdrVal;
TInt err = headers.GetField(contLength,0,tempHdrVal);
if(err == KErrNone)
{
iRemoteFileSize = tempHdrVal.Int();
}
else
{
iRemoteFileSize = 0;
}

here iRemoteFileSize is the total file size of the file being downloaded. If for some reason the file size cannot be acquired set it to zero, in this case progress cannot be shown.

Show progress

Use the case EGotResponseBodyData for this

MHTTPDataSupplier* dataSupplier = aTransaction.Response().Body();
TPtrC8 ptr;
dataSupplier->GetNextDataPart(ptr);
 
TInt kb=0;
TBuf<100> str;
 
iBytes = iBytes + ptr.Length();
kb=iBytes;
if(iRemoteFileSize >0 && kb > 1024) // show percentage
{
kb=(TInt)((kb*100)/iRemoteFileSize);
_LIT(KFormat,"%d %% Recieved");
str.Format(KFormat,kb);
iDlg->SetTextL(str);
}
else
{
if(kb < 1024)
{
_LIT(KFormat,"Receiving File : %d Bytes"); //show bytes
str.Format(KFormat,kb);
iDlg->SetTextL(str);
}
else
{
kb = (TInt) kb/1024;
_LIT(KFormat,"Receiving File : %d KB"); // show in kb
str.Format(KFormat,kb);
iDlg->SetTextL(str);
}
}

here iDlg (CAknWaitDialog) is used to show the progress of the download.

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia