I read wiki article
http://www.developer.nokia.com/Commu...part/form-data
and want to know how to use it in my GUI application
I read wiki article
http://www.developer.nokia.com/Commu...part/form-data
and want to know how to use it in my GUI application
I really need help and not getting any clue how to use this article in my app to upload a image.. Champions please help
If you are new with the HTTP API set, it may be better to check complete examples first, like the GUI-less exampleclient (expect it somewhere as AppProts\exampleclient folder somewhere under Examples), and the GUI-based WebClient example (in S60Ex or gui examples depending of the given SDK). These just work as they are provided, so you can check and debug them.
Since you want uploading from a GUI code, the WebClient example can be a good pick to add the upload functionality, since it already has most of the required objects and methods.
Na.. actually I am not newto HTTP API set. Earlier also I uploaded simple text files using HTTP WebClient. But this time have to deal with images and not able to understand how and where to merge the code in my app.
Try following what has been done in that wiki article & merge it accordingly in your code.Give it a try, & then post your queries here for any further help.
If you know handling of incoming data, you already know MHTTPDataSupplier, since that is what you are getting the data from when EGotResponseBodyData comes. When posting data you are the one who implements this interface, and the HTTP framework is going to use it for getting the data from you. The "untitled" code blocks between "POST code Get the file you want to upload in binary format" and "Submit the transaction" show how to prepare this data, with multipart headers and delimiters. They are not coming from the air, but they are prescribed by the HTTP standard. Search for multipart rfc (with Google for example) to get the related specifications.
Now When i succeeded in implementing that wiki article, don't know why but getting Kern Exec 3 in following code of ClientEngine class:
RStringF method = iSession.StringPool().StringF(HTTP::EPOST,RHTTPSession::GetTable());
All variables are allocated memory sucessfully, but I am still getting Kern exec 3. Is there any way to avoid this panic
Infact I am getting Kern exec 3 while creating Post request in IssueHttpPostL method. Seems like I am trying to execute some invalid instructions, but how to know which instruction is invalid??
I checked my code. The piece of code where I am getting panic not having any pointer. and,even memory is allocated properly. What could be other possible reasons for this panic
TBool CClientEngine::PreparePostImage(TPtr8 i)
{
/* RFs aFs;
User::LeaveIfError(aFs.Connect());
CleanupClosePushL(aFs);
RFile aFile;
User::LeaveIfError(aFile.Open(aFs, imagefilename, EFileRead|EFileShareAny));
TInt aSize;
User::LeaveIfError(aFile.Size(aSize));
HBufC8* iPostDataImage = HBufC8::NewL(aSize);
CleanupStack::PushL(iPostDataImage);
TPtr8 aPtr = iPostDataImage->Des();
//Obviously we have to read in the data to the iPostDataImage (ray)
TInt i=aFile.Read(0, aPtr, aSize);
aFile.Close();
aFs.Close();*/
// CleanupStack::PopAndDestroy(&aFs);
_LIT8(KDataStart,"--AaB03x");
_LIT8(KCrlf,"\r\n");
_LIT8(KContent,"Content-Disposition: form-data; name='userfile'; filename='");
_LIT8(KFileCompletion,"'");
_LIT(KContent2,"Content-Type: image/jpg");
_LIT(KContent3,"Content-Transfer-Encoding: binary");
_LIT8(KDataEnd,"--AaB03x--");
_LIT8(KContentType,"image/jpg");
/* if(iPostData)
{
delete iPostData;
}*/
TInt a=i.Length();
iPostData = HBufC8::NewL(650+i.Length());
TPtr8 iPostDataPtr1 = iPostData->Des();
/* iPostDataPtr.Zero();
iPostDataPtr.Append(KCrlf);
iPostDataPtr.Append(KDataStart);
iPostDataPtr.Append(KCrlf);
iPostDataPtr.Append(KContent);
iPostDataPtr.Append(imagefilename);
iPostDataPtr.Append(KFileCompletion);
iPostDataPtr.Append(KCrlf);
iPostDataPtr.Append(KContent2);
iPostDataPtr.Append(KCrlf);
iPostDataPtr.Append(KContent3);
iPostDataPtr.Append(KCrlf);
iPostDataPtr.Append(KCrlf);
iPostDataPtr.Append(aPtr); //the file in binary
iPostDataPtr.Append(KCrlf);
iPostDataPtr.Append(KDataEnd);
iPostDataPtr.Append(KCrlf);*/
iPostDataPtr1.Append(i);
TBuf<1000> uri;
uri.Append(_L("http:\\www.softservices.org\\newsymb.php?imei="));
uri.Append(_L("1234"));
TBuf8<1000> uri8;
uri8.Copy(uri);
TBuf8<20> h;
h.Append(_L("hey!!@@"));
IssueHTTPPostL(uri8,KContentType,h);
// CleanupStack::Pop(iPostDataImage);
/*
RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
SetHeaderL(hdr, HTTP::EAccept, KAccept);
SetHeaderL(hdr, HTTP::EContentType, KPostContentType);
MHTTPDataSupplier* dataSupplier = this;
iTransaction.Request().SetBody(*dataSupplier);
iTransaction.SubmitL();*/
return ETrue;
}
*=======================================================*
void CClientEngine::IssueHTTPPostL(const TDesC8& aUri,
const TDesC8& aContentType,
const TDesC8& aBody)
{
RDebug::RawPrint(_L("in issueHTTPpostL"));
// Parse string to URI
TUriParser8 uri;
uri.Parse(aUri);
// Copy data to be posted into member variable; iPostData is used later in
// methods inherited from MHTTPDataSupplier.
delete iPostData;
iPostData = 0;
iPostData = aBody.AllocL();
// Create HTTP connection
if(iConnectionSetupDone==true)
{
TRAPD(err,SetupConnectionL();CleanupStack::Pop());
// User didn't select an IAP
if (err == KErrNotReady) {
// HBufC* resTxCancelled = StringLoader::LoadLC(R_HTTP_TX_CANCELLED);
iObserver.ClientEvent(_L("transaction cancelled"));
// CleanupStack::PopAndDestroy(resTxCancelled);
return;
}
}
// Get request method string for HTTP POST
RStringF method;
TRAPD(err1, method = iSession.StringPool().StringF(HTTP::EPOST,RHTTPSession::GetTable()));
// Open transaction with previous method and parsed uri. This class will
// receive transaction events in MHFRunL and MHFRunError.
// iTransaction = iSession.OpenTransactionL(uri, *this, method);
// Set headers for request; user agent, accepted content type and body's
// content type.
RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
// RHTTPHeaders hdr;
SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
SetHeaderL(hdr, HTTP::EAccept, KAccept);
SetHeaderL(hdr, HTTP::EContentType, aContentType);
// Set this class as an data supplier. Inherited MHTTPDataSupplier methods
// are called when framework needs to send body data.
MHTTPDataSupplier* dataSupplier = this;
iTransaction.Request().SetBody(*dataSupplier);
// Submit the transaction. After this the framework will give transaction
// events via MHFRunL and MHFRunError.
iTransaction.SubmitL();
iRunning = ETrue;
// HBufC* resConnecting = StringLoader::LoadLC(R_HTTP_CONNECTING);
iObserver.ClientEvent(_L("client connecting"));
// CleanupStack::PopAndDestroy(resConnecting);
RDebug::RawPrint(_L("exiting issueHTTPpostL"));
}
TBool CClientEngine::PreparePostImage(TPtr8 i)
{
/* RFs aFs;
User::LeaveIfError(aFs.Connect());
CleanupClosePushL(aFs);
RFile aFile;
User::LeaveIfError(aFile.Open(aFs, imagefilename, EFileRead|EFileShareAny));
TInt aSize;
User::LeaveIfError(aFile.Size(aSize));
HBufC8* iPostDataImage = HBufC8::NewL(aSize);
CleanupStack::PushL(iPostDataImage);
TPtr8 aPtr = iPostDataImage->Des();
//Obviously we have to read in the data to the iPostDataImage (ray)
TInt i=aFile.Read(0, aPtr, aSize);
aFile.Close();
aFs.Close();*/
// CleanupStack::PopAndDestroy(&aFs);
_LIT8(KDataStart,"--AaB03x");
_LIT8(KCrlf,"\r\n");
_LIT8(KContent,"Content-Disposition: form-data; name='userfile'; filename='");
_LIT8(KFileCompletion,"'");
_LIT(KContent2,"Content-Type: image/jpg");
_LIT(KContent3,"Content-Transfer-Encoding: binary");
_LIT8(KDataEnd,"--AaB03x--");
_LIT8(KContentType,"image/jpg");
/* if(iPostData)
{
delete iPostData;
}*/
TInt a=i.Length();
iPostData = HBufC8::NewL(650+i.Length());
TPtr8 iPostDataPtr1 = iPostData->Des();
/* iPostDataPtr.Zero();
iPostDataPtr.Append(KCrlf);
iPostDataPtr.Append(KDataStart);
iPostDataPtr.Append(KCrlf);
iPostDataPtr.Append(KContent);
iPostDataPtr.Append(imagefilename);
iPostDataPtr.Append(KFileCompletion);
iPostDataPtr.Append(KCrlf);
iPostDataPtr.Append(KContent2);
iPostDataPtr.Append(KCrlf);
iPostDataPtr.Append(KContent3);
iPostDataPtr.Append(KCrlf);
iPostDataPtr.Append(KCrlf);
iPostDataPtr.Append(aPtr); //the file in binary
iPostDataPtr.Append(KCrlf);
iPostDataPtr.Append(KDataEnd);
iPostDataPtr.Append(KCrlf);*/
iPostDataPtr1.Append(i);
TBuf<1000> uri;
uri.Append(_L("http:\\www.softservices.org\\newsymb.php?imei="));
uri.Append(_L("1234"));
TBuf8<1000> uri8;
uri8.Copy(uri);
TBuf8<20> h;
h.Append(_L("hey!!@@"));
IssueHTTPPostL(uri8,KContentType,h);
// CleanupStack::Pop(iPostDataImage);
/*
RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
SetHeaderL(hdr, HTTP::EAccept, KAccept);
SetHeaderL(hdr, HTTP::EContentType, KPostContentType);
MHTTPDataSupplier* dataSupplier = this;
iTransaction.Request().SetBody(*dataSupplier);
iTransaction.SubmitL();*/
return ETrue;
}
*=======================================================*
void CClientEngine::IssueHTTPPostL(const TDesC8& aUri,
const TDesC8& aContentType,
const TDesC8& aBody)
{
RDebug::RawPrint(_L("in issueHTTPpostL"));
// Parse string to URI
TUriParser8 uri;
uri.Parse(aUri);
// Copy data to be posted into member variable; iPostData is used later in
// methods inherited from MHTTPDataSupplier.
delete iPostData;
iPostData = 0;
iPostData = aBody.AllocL();
// Create HTTP connection
if(iConnectionSetupDone==true)
{
TRAPD(err,SetupConnectionL();CleanupStack::Pop());
// User didn't select an IAP
if (err == KErrNotReady) {
// HBufC* resTxCancelled = StringLoader::LoadLC(R_HTTP_TX_CANCELLED);
iObserver.ClientEvent(_L("transaction cancelled"));
// CleanupStack::PopAndDestroy(resTxCancelled);
return;
}
}
// Get request method string for HTTP POST
RStringF method;
TRAPD(err1, method = iSession.StringPool().StringF(HTTP::EPOST,RHTTPSession::GetTable()));
// Open transaction with previous method and parsed uri. This class will
// receive transaction events in MHFRunL and MHFRunError.
// iTransaction = iSession.OpenTransactionL(uri, *this, method);
// Set headers for request; user agent, accepted content type and body's
// content type.
RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
// RHTTPHeaders hdr;
SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
SetHeaderL(hdr, HTTP::EAccept, KAccept);
SetHeaderL(hdr, HTTP::EContentType, aContentType);
// Set this class as an data supplier. Inherited MHTTPDataSupplier methods
// are called when framework needs to send body data.
MHTTPDataSupplier* dataSupplier = this;
iTransaction.Request().SetBody(*dataSupplier);
// Submit the transaction. After this the framework will give transaction
// events via MHFRunL and MHFRunError.
iTransaction.SubmitL();
iRunning = ETrue;
// HBufC* resConnecting = StringLoader::LoadLC(R_HTTP_CONNECTING);
iObserver.ClientEvent(_L("client connecting"));
// CleanupStack::PopAndDestroy(resConnecting);
RDebug::RawPrint(_L("exiting issueHTTPpostL"));
}
In IssueHttpPostL method I am getting Kern Exec 3 apnic after declaring RStringF method.
so you are talking about these lines:
Have you checked iSession here? Is it NULL or not?Code:RStringF method; TRAPD(err1, method = iSession.StringPool().StringF(HTTP::EPOST,RHTTPSession::GetTable()));