Languages

Menu
Sites
Language
Image DecodeUrl IHttpTransactionEventListener

Hello,

Im trying to load an image from a remote url.

I am using DecodeUrl, but keep getting  the following error:

09-30 22:59:49.331 : ERROR / Tizen::Net::Http ( 6361 : 6361 ) : result Tizen::Net::Http::_HttpTransactionImpl::Dispose()(284) > [E_INVALID_STATE] HttpTransaction[0] is already closed.

I confirm that i can access remote Web Services using IHttpTransactionEventListener contract.

Here is my sample code:

result
MainForm::OnInitializing(void)
{   
    (...)
    Image img;
    RequestId reqId;
    Uri _uri;
    img.Construct();
    
    _uri.SetUri(L"http://www.somesite.com/images/chann_26_2919.png");
    img.DecodeUrl(_uri, BITMAP_PIXEL_FORMAT_RGB565, 20, 20, reqId, *this, img.TIMEOUT_INFINITE);
    
    (...)
    return result;
}

(..)

void
MainForm::OnImageDecodeUrlReceived (RequestId reqId, Bitmap *pBitmap, result r, const String errorCode, const String errorMessage)
{   
	AppLog("OnImageDecodeUrlReceived");//not called!	
}

Can anyone help me out with this? Is there any example i can follow to help me with this?

 

Thanks

Nuno

 

View Selected Answer

Responses

3 Replies
Jirka Prazak

Hi there,

not sure why this does not work, but I have just done something similar but differently and it works, this is the setup method to get start the transaction

SomeClass::Setup(void) {

HttpSession* pSession = null;
HttpTransaction* pTransaction = null;
HttpRequest* pRequest = null;
HttpHeader* pHeader = null;

// Creates an HTTP session.
pSession = new HttpSession();
r = pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, null, hostAddr,
	null);
if (r != E_SUCCESS) {
	AppLogException("Error constructing http session", GetErrorMessage(r));
		return r;
}

pTransaction = pSession->OpenTransactionN();
r = pTransaction->AddHttpTransactionListener(*this);

pRequest = pTransaction->GetRequest();
pRequest->SetMethod(NET_HTTP_METHOD_GET);

r = pRequest->SetUri(mapUri);
if (r != E_SUCCESS) {
	AppLogException(
		"Error setting URI", GetErrorMessage(r));
	return r;
}

pHeader = pRequest->GetHeader();
r = pHeader->AddField("Accept", "image/jpeg");
if (r != E_SUCCESS) {
	AppLogException("Error adding field to header ", GetErrorMessage(r));
			return r;
}

r = pTransaction->Submit();
if (r != E_SUCCESS) {
	AppLogException(
		"Error submitting http transaction", GetErrorMessage(r));
	return r;
}}

And here is the callback method from the IHttpTransactionEventListener interface

void SomeClass::OnTransactionCompleted(
    	Tizen::Net::Http::HttpSession& httpSession,
		Tizen::Net::Http::HttpTransaction& httpTransaction) {
	
result r = E_SUCCESS;
HttpResponse* pHttpResponse = null;

pHttpResponse = httpTransaction.GetResponse();

if (pHttpResponse->GetHttpStatusCode() == HTTP_STATUS_OK) {
	ImageBuffer* pBuffer = pHttpResponse->ReadBodyN();
AppLog(
	"Successfully got image buffer with size %d", __pMapBuffer->GetLimit());
}

delete &httpTransaction;
delete &httpSession;

//... do stuff with the image buffer

return r;
}

Make sure you don't forget to delete the session and stuff, 10 is max and you run out pretty quick if you want to do it for more reqs.  If you figure it out your way let me know because it is much less code.

-Jirka

nuno filipe

Thx Jirka,

I was in fact trying this aproach aswell... I guess its another alternative :)

Regards

Nuno

Mark as answer
Jirka Prazak

I think I know where your problem is,

Remarks:
  • If the operation succeeds then r is E_SUCCESS, otherwise r is an error code.
  • The Image object must not be deleted in this event listener.
  • This method passes an auto-scaled bitmap,
    so the dimension can be different from the requested dimension if the passed bitmap is locked.

which means that you have to declare the image as a field of the class, the way you have it now image is lost as you leave the function because it is declared there and thus is no longer available when the callback function is called.

-Jirka