×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Jul 2005
    Posts
    95

    Downloading a Binary File using HTTP GET

    Hi ,

    I am trying to download an image file using the HTTP API. I am able to successfully download and display a text file.
    However, when I download an image file , the file gets downloaded but the image says no preview available also if i try to download an audio file , the file gets downloaded but cannot be played.In other words any binary file I download is not usable.
    For example, given below is the code when trying to download a bmp file called someimage.bmp.

    My GetRequestL() function defined in the HTTP Engine is as follows :

    Code:
    	void CHTTPExampleEngine::GetRequestL(const TDesC& aUri)
    	{
    		// Parse the URI
    		ParseUriL(aUri);
    
    		// Create the transaction
    		iTransaction = iSession.OpenTransactionL(iUriParser, *this,
    		iSession.StringPool().StringF(HTTP::EGET, RHTTPSession::GetTable()));
    
    		// Set transaction headers
    		RHTTPHeaders headers = iTransaction.Request().GetHeaderCollection();
    		AddHeaderL(headers, HTTP::EUserAgent, KUserAgent);
    		AddHeaderL(headers, HTTP::EAccept, KAccept);
    
    		// Submit the request
    		iTransaction.SubmitL();
    	}
    where KUserAgent is defined as : _LIT8(KUserAgent, "HTTPExample (1.0)");
    and KAccept is defined as _LIT8(KAccept, "*/*");

    My ResponseReceivedL() function in the observer class is as follows :

    Code:
    void CHTTPExampleAppUi::ResponseReceivedL(const TDesC& aResponse)
        {
    	
       	
    
       	iAppContainer->SetTextL(_L("Download Complete")); //Show message in Rich Text Editor
    
       	//Write to file
    
        	RFs fsSession;
        	User::LeaveIfError(fsSession.Connect());
    
       	_LIT(KMyFile,"c:\\someimage.bmp");
    
        	RFile myFile;
        	TRAPD(err,myFile.Create(fsSession,KMyFile,EFileShareExclusive|EFileWrite));
    
        	if(err != KErrNone)
          		iLog.WriteFormat(_L("Error = %d"),err);
        	else
          		iLog.Write(_L("No Error"));
    
    
        	myFile.Write(DES_AS_8_BIT(aResponse));
    
            fsSession.Close();
    
    
    
    
        }
    DES_AS_8_BIT is defined as : #define DES_AS_8_BIT(str) (TPtrC8((TText8*)((str).Ptr()), (str).Size())) for converting 16 bit data to 8 bit.
    I have tried using audio/* , image/* etc also as the value for KAccept but it still does not work.Do I need to save the downloaded binary file in a different way than the way I am doing above ?

    Thanks a lot

  2. #2
    Nokia Developer Expert
    Join Date
    Jul 2003
    Location
    Vancouver, Canada
    Posts
    220

    Re: Downloading a Binary File using HTTP GET

    Have you used www.ethereal.com or usch to capture your trace from your phone to your server. It will help you understand what is wring with your request.

    Hope this helps

  3. #3
    Regular Contributor
    Join Date
    Jul 2005
    Posts
    95

    Re: Downloading a Binary File using HTTP GET

    Hi bill,

    Thanks for the reply. The program works now when I convert all 16 bit data to 8 bit in my MHFRunL(). The problem was occurring because RHTTP works only with 8 bit data.

    Thanks again

  4. #4
    Nokia Developer Expert
    Join Date
    Jul 2003
    Location
    Vancouver, Canada
    Posts
    220

    Cool Re: Downloading a Binary File using HTTP GET

    Nice, glad you fixed your problem

  5. #5
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: Downloading a Binary File using HTTP GET

    hi razas,

    Can you share the example code to download a image/audio file ? Thanks in advance if you could, else how to go about it !
    Amit Kankani
    Nokia Developer Champion

  6. #6
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: Downloading a Binary File using HTTP GET

    hi,

    i was able to download and play a mp3 file... !

    however, i also wanted to compile it for s60 sdk 1.2 ! this doesn't support http client api ! so will have to use RSocket !!! any idea how to go about ?
    Amit Kankani
    Nokia Developer Champion

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    19

    Re: Downloading a Binary File using HTTP GET

    Hi amitkankani,

    I have read you were able to download and play a mp3 file.

    Can you share the example code to play a mp3 file?

    Thanks in advance.
    -------------------------------
    Francisco de la Torre
    Spain
    S60 2nd FP2 + CodeWarrior 3.1
    Nokia 6630
    -------------------------------

  8. #8
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: Downloading a Binary File using HTTP GET

    how to play a mp3 file ?

    well take reference from AudioStreamExample

    http://www.forum.nokia.com/info/sw.n..._0_en.zip.html

    also search for stream audio in forum nokia main site.. hope u ll find more references ....

    hope this helps
    Amit Kankani
    Nokia Developer Champion

  9. #9
    Registered User
    Join Date
    Apr 2007
    Posts
    19

    Re: Downloading a Binary File using HTTP GET

    Thanks amitkankani!

    Done!
    -------------------------------
    Francisco de la Torre
    Spain
    S60 2nd FP2 + CodeWarrior 3.1
    Nokia 6630
    -------------------------------

Similar Threads

  1. File corrupted - with signed sis
    By annehj in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 4
    Last Post: 2007-12-10, 13:44
  2. downloading jar file...
    By jeremiah05 in forum Mobile Java General
    Replies: 4
    Last Post: 2006-05-13, 08:16
  3. Replies: 3
    Last Post: 2006-05-02, 20:12
  4. Replies: 1
    Last Post: 2005-07-26, 14:59
  5. J2ME question concerning binary file input
    By dwneonstar in forum Mobile Java General
    Replies: 1
    Last Post: 2003-11-24, 17:12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •