how to download an image from an URL and display on the mobile screen using HTTP?

Login to reply to this topic.
Wed, 2008-01-09 10:05
Joined: 2007-07-31
Forum posts: 123

Hi everybody,

can any body tell me how would i be able to download an image from an URL using HTTP ? Please give some code to download images from the server .

Actually i want to download an image file from server connected with the internet on my mobile phone and to display on the screen.

Please paste some code to download images from the server .

i shall be thankfull to you...

Brajesh...


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++


Wed, 2008-01-09 10:29
Joined: 2005-11-20
Forum posts: 1058
Downloading and displaying pictures

You download a picture exactly like you download any other file: Specify the URL of the picture in the HTTP client and download. There is a nice HTTP client example in the SDK that you can study to learn how to do this.

And, once you have downloaded the picture, the second task of displaying it on the screen of course does not depend on how you got the picture to your phone. There is also a lot of sample code around about how to display pictures.

Just pasting some code here showing all this, as you asked for in your post, is a little difficult: This will be quite some amount of code, and probably nobody will it have ready just like you need it.


René Brunner

Wed, 2008-01-09 10:44
Joined: 2007-07-31
Forum posts: 123
Re: how to download an image from an URL and display on the mobi

ok thanks i am going to try...myself

but i did not find the HTTP example in the symbian sdk...

Brajesh...


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

Wed, 2008-01-09 11:37
Joined: 2005-11-20
Forum posts: 1058
Samples

Don't know, can't check at the moment.

You might find something here as well:
http://www.forum.nokia.com/main/resources/technologies/symbian/documentation/networking.html


René Brunner

Thu, 2008-01-10 08:48
Joined: 2007-07-31
Forum posts: 123
Re: how to download an image from an URL and display on the mobi

/**
* Initiate a GET request
*
* @param aUri The URI to get
*/
void CHTTPExampleEngine::GetRequestL(const TDesC& aUri)
        {
        _LIT8(KAccept, "audio/*");
        // 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();
        }
/**
* Add a header to a header set
*
* @param aHeaders The header set to be modified
* @param aHeaderField The name of the header to be added
* @param aHeaderValue The value for the header to be added
*/
void CHTTPExampleEngine::AddHeaderL(RHTTPHeaders aHeaders, TInt aHeaderField, const TDesC8& aHeaderValue)
        {
        RStringPool stringPool = iSession.StringPool();
        RStringF valStr = stringPool.OpenFStringL(aHeaderValue);
        THTTPHdrVal headerVal(valStr);
        aHeaders.SetFieldL(stringPool.StringF(aHeaderField, RHTTPSession::GetTable()), headerVal);
        valStr.Close();
        }

the above code is working fine when i download a streamed audio but now i want to download a bmp file.I given uri of bmp file but now the statusBuf gives status "Not Acceptable" in the following code.

void CHTTPExampleEngine::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
        {
        switch (aEvent.iStatus)
                {
                case THTTPEvent::EGotResponseHeaders:
                        {
                        // HTTP response headers have been received.
                        // Pass status information to observer.
                        RHTTPResponse resp = aTransaction.Response();

                        // Get status code
                        TInt statusCode = resp.StatusCode();

                        // Get status text
                        RStringF statusStr = resp.StatusText();
                        HBufC* statusBuf = HBufC::NewLC(statusStr.DesC().Length());
                        statusBuf->Des().Copy(statusStr.DesC());

                        // Inform observer
                        iObserver.ResponseStatusL(statusCode, *statusBuf);

                        CleanupStack::PopAndDestroy(statusBuf);
                       
                       
                        }
                        break;


                case THTTPEvent::EGotResponseBodyData:
                       
                        break;

                case THTTPEvent::EResponseComplete:
                       
                        break;
                }
        }

Hi,
Please tell me solution .What should be the value of KAccept i think audio is not correct for bmp file

Thanks in advance...

Brajesh....


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

Thu, 2008-01-10 11:12
Joined: 2005-11-20
Forum posts: 1058
Bitmap mime types

That would be "image/*" for any type of image, or more specific "image/x-ms-bmp" for a Windows bitmap.


René Brunner

Thu, 2008-01-10 11:55
Joined: 2007-07-31
Forum posts: 123
Re: how to download an image from an URL and display on the mobi

yes this was to do.........it is ok now

thanks...


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

Wed, 2008-02-06 05:35
Joined: 2007-06-13
Forum posts: 2
Re: how to download an image from an URL

Hi,

I am also working on the same requirement. I just want to put the image buffer into a separate file of the private folder. Can anyone answer where does I get the image buffer in the above code?

Thanks.....

Fri, 2008-05-23 06:32
Joined: 2008-05-23
Forum posts: 1
Re: how to download an image from an URL and display on the mobi

Hello,

Me too working on the display of image on the mobile screen after pushing a url.
I am able to read and display text on the screen, but the concern is on displaying a bitmap image from the server.
Am presently working on the HTTP Client example available in forum.nokia.com

the steps involved are as follows:

* In ClientEngine.cpp
_LIT8(KAccept, "image/x-ms-bmp"); // added this to set the Mime type as an image
* view.h
class CEikImage;
CEikImage* iFriendImage; //added the two lines

//void AddToOutputWindowL(const TDesC8& aText); //commented for text
void AddToOutputWindowL(const TDesC8& aBitmap); // added for image display

* In View.cpp

void CClientAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();

// Create output window
iOutputWindow = new (ELeave) CEikRichTextEditor();
iOutputWindow->SetContainerWindowL(*this);
iOutputWindow->ConstructL(this, KNumberOfLines, KTextLimit,
EEikEdwinReadOnly, EGulFontControlAll, EGulNoSymbolFonts);

//Initialing Image Control
iFriendImage = new (ELeave) CEikImage; //added here for image display
iFriendImage->SetContainerWindowL(*this); // added this line too

// Create status window
iStatusWindow = new (ELeave) CEikRichTextEditor();
iStatusWindow->SetContainerWindowL(*this);
iStatusWindow->ConstructL(this, KNumberOfLines, KTextLimit,
EEikEdwinReadOnly|EEikEdwinNoWrap,
EGulFontControlAll, EGulNoSymbolFonts);

iStatusWindow->SetFocus(ETrue);

// Set the windows size
SetRect(aRect);

// Activate the window, which makes it ready to be drawn
ActivateL();
}

* Also in view.cpp
void CClientAppView::AddToOutputWindowL(const TDesC8& aBitmap)
{

CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
CleanupStack::PushL(bitmap);
//CEikImage* iFriendImage = new (ELeave) CEikImage;
iFriendImage->SetBitmap(bitmap);
iFriendImage->SetPictureOwnedExternally(ETrue);
iFriendImage->MakeVisible(ETrue);
//CEikImage* bitmap = new (ELeave) CEikImage();
// //bitmap->SetBitmap(bitmap);
// bitmap->SetPictureOwnedExternally(ETrue);
// bitmap->MakeVisible(ETrue);
CleanupStack::PopAndDestroy(bitmap); // tempBuf
}

The error says unreferenced formal parameter aBitmap in void CClientAppView::AddToOutputWindowL(const TDesC8& aBitmap)....

Please do the needful folks..

Thanks in advance
Veena Naidu

  • Login to reply to this topic.