Categories: Symbian C++ | How To | Code Examples | HTTP | Download | Files/Data
This page was last modified 08:34, 8 December 2007.
How to download a file on the device
From Forum Nokia Wiki
The following article shows how to use the HTTP Client to download and store a file on the device.
Before the transaction
The file download can be initiated using the GET Method of the HTTP Client. But to store the file being downloaded the following needs to be done: (in the get method itself)
- Create a file on the device.
_LIT(KXMLFilePath, "c:\\mytempfiles\\"); iCurrentFileName.Append(_L("default.xml")); TInt err=iRFileObj.Open(iFsSession,iCurrentFileName,EFileWrite); if (err==KErrNotFound) // file does not exist - create it { err=iRFileObj.Create(iFsSession,iCurrentFileName,EFileWrite); }
once created the file contents are appended as the download happens.
- Initiate the transaction for the file to download
A file download can happen as a GET to a particular URL, e.g. http://www.foo.com/myfile.xml, here the file to download is myfile.xml. This file will downloaded and stored as default.xml in our example.
During the transaction
Once the GET has started use the following code in MHFRunL to store the file
case THTTPEvent::EGotResponseBodyData: // Get text of response body MHTTPDataSupplier* dataSupplier = aTransaction.Response().Body(); TPtrC8 ptr; dataSupplier->GetNextDataPart(ptr); TInt aPos=0; iRFileObj.Seek(ESeekCurrent, aPos); iRFileObj.Write(ptr); //save the file being downloaded HBufC* buf = HBufC::NewLC(ptr.Length()); buf->Des().Copy(ptr); if (!iResponseBuffer) { iResponseBuffer = buf->AllocL(); } else { iResponseBuffer = iResponseBuffer->ReAllocL(iResponseBuffer->Length()+buf->Length()); iResponseBuffer->Des().Copy(*buf); } // Release buf CleanupStack::PopAndDestroy(buf); // Release the body data dataSupplier->ReleaseData();
Now the file has been stored and can be accessed at "C:\\mytempfiles\\default.xml"
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sis file via WAP gateway | amardeep | General Browsing | 1 | 2003-04-01 04:46 |
| IMPORTANT: Carbide c++ 1.2 download errors. Need to use Nokia Downloader | jimgilmour1 | Carbide.c++ and CodeWarrior Tools | 1 | 2007-04-30 16:15 |
| wav file download to 7650 via wap | davidchin | General Browsing | 2 | 2003-04-10 11:04 |
| is there a File class equivalent in J2ME? | rj_cybersilver | Mobile Java General | 44 | 2007-08-18 15:51 |
| detecting other device BT off (urgent) | pv123 | Bluetooth Technology | 1 | 2007-12-21 14:49 |
