×
Namespaces

Variants
Actions

How to show file download progress using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: rathodavinash (28 Jun 2007)
Last edited: hamishwillee (21 May 2013)

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.

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.

This page was last modified on 21 May 2013, at 03:50.
55 page views in the last 30 days.
×