I have a problem with storing downloaded contents (a gif file) after it has been downloaded. I create a download as follows
Code:
EXPORT_C TInt CFileDownloaderBase::Download(
const TDesC& aUrl, const TDesC& aDestFileName)
{
TInt result = KErrArgument;
if(!aUrl.Length())
return result;
TInt iapId=api::SB_GetSettingLong(STE_IAPID,-1);
if(iapId==-1)
return KErrCouldNotConnect;
try
{
START_SYMBIAN_EXCEPTION_HANDLING
//Set IAP
User::LeaveIfError(iDownloadMgr.SetIntAttribute(EDlMgrIap, iapId));
//Convert to UTF8
HBufC8* pUrl = putils::UnicodeToUTF8L(aUrl);
CleanupStack::PushL(pUrl);
TBool bResult;
RHttpDownload& download=iDownloadMgr.CreateDownloadL((*pUrl),bResult);
CleanupStack::PopAndDestroy(pUrl);
if(!bResult) User::Leave(KErrAlreadyExists);
TInt error = download.SetStringAttribute(
EDlAttrDestFilename,aDestFileName);
//error is set to KErrArgument - why?
User::LeaveIfError(
download.SetIntAttribute( EDlAttrAction, EDoNothing ) );
User::LeaveIfError( download.Start() );
result = KErrNone;
FINISH_SYMBIAN_EXCEPTION_HANDLING
}
catch(XLeaveException& e)
{
result = e.Reason();
DPRINT(_L8("CFileDownloaderBase::Download - Exception (%d)"),result);
}
return result;
}
The download starts fine and as far as I can understand it completes with no problem
Code:
EXPORT_C void CFileDownloaderBase::HandleDMgrEventL(
RHttpDownload& aDownload, THttpDownloadEvent aEvent )
{
DPRINT(_L8("CFileDownloaderBase::HandleDMgrEventL - "
"iDownloadState(%d),iProgressState(%d)"),
aEvent.iDownloadState,aEvent.iProgressState);
switch(aEvent.iDownloadState)
{
case EHttpDlPaused:
if( aEvent.iProgressState==EHttpContentTypeReceived)
aDownload.Start();
break;
case EHttpDlCompleted:
{
if( aEvent.iProgressState==EHttpProgNone)
{
TFileName filename( _L("c:\\system\\temp\\myfile.gif" ));
TInt error = aDownload.SetStringAttribute( EDlAttrDestFilename, filename );
error = aDownload.Move();
}
break;
} //end case EHttpDlCompleted:
} //end switch(aEvent.iDownloadState)
}
I print the result of the execution into a file and here is the output
13/5/2009 13:16:33 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(2),iProgressState(2054)
13/5/2009 13:16:33 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(1),iProgressState(0)
13/5/2009 13:16:33 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(2),iProgressState(500)
13/5/2009 13:16:33 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(2),iProgressState(1000)
13/5/2009 13:16:34 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(2),iProgressState(1020)
13/5/2009 13:16:34 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(2),iProgressState(2020)
13/5/2009 13:16:34 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(3),iProgressState(2021)
13/5/2009 13:16:34 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(2),iProgressState(500)
13/5/2009 13:16:34 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(2),iProgressState(1000)
13/5/2009 13:16:34 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(2),iProgressState(1020)
13/5/2009 13:16:34 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(2),iProgressState(2030)
13/5/2009 13:16:35 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(2),iProgressState(2050)
13/5/2009 13:16:35 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(2),iProgressState(3002)
13/5/2009 13:16:35 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(2),iProgressState(2051)
13/5/2009 13:16:35 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(2),iProgressState(2051)
13/5/2009 13:16:35 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(2),iProgressState(2051)
13/5/2009 13:16:35 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(4),iProgressState(0)
13/5/2009 13:16:35 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(4),iProgressState(3000)
13/5/2009 13:16:35 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(4),iProgressState(3005)
13/5/2009 13:16:36 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(4),iProgressState(3003)
13/5/2009 13:17:37 pdmData.cpp,1870 CFileDownloaderBase::HandleDMgrEventL - iDownloadState(13),iProgressState(0)
As you can see the complete operation finishes successfully but I still do not have my gif file in
c:\\system\\temp\\myfile.gif.
Any idea what I am doing wrong? Thanks