Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 09:57, 26 November 2007.

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.

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.

Related Discussions
Thread Thread Starter Forum Replies Last Post
MMS not received! sharibanis Symbian Tools & SDKs 1 2003-12-08 03:28
MMS not received! sharibanis Symbian Tools & SDKs 1 2003-12-08 03:26
How to create Video MMS .... for 7650 TrickLo General Messaging 3 2003-12-08 03:28
MMS not received! sharibanis General Symbian C++ 1 2003-12-08 03:27
Series 60 1.2 SDK sci0x Symbian 6 2003-11-30 06:25
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX