×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    54

    how to use http mutipart/form data wiki example to upload a image

    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

  2. #2
    Registered User
    Join Date
    Jun 2012
    Posts
    54

    Re: how to use http mutipart/form data wiki example to upload a image

    I really need help and not getting any clue how to use this article in my app to upload a image.. Champions please help

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,567

    Re: how to use http mutipart/form data wiki example to upload a image

    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.

  4. #4
    Registered User
    Join Date
    Jun 2012
    Posts
    54

    Re: how to use http mutipart/form data wiki example to upload a image

    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.

  5. #5
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    3,956

    Re: how to use http mutipart/form data wiki example to upload a image

    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.

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,567

    Re: how to use http mutipart/form data wiki example to upload a image

    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.

  7. #7
    Registered User
    Join Date
    Jun 2012
    Posts
    54

    Re: how to use http mutipart/form data wiki example to upload a image

    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

  8. #8
    Registered User
    Join Date
    Jun 2012
    Posts
    54

    Re: how to use http mutipart/form data wiki example to upload a image

    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??

  9. #9
    Nokia Developer Champion
    Join Date
    Nov 2011
    Location
    India
    Posts
    360

    Re: how to use http mutipart/form data wiki example to upload a image

    Quote Originally Posted by preety.saini View Post
    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??
    Kern Exec 3 means any of your object is referring to a invalid memory location or is NULL. So, you can debug your code to check which piece of line is causing the issue.

  10. #10
    Registered User
    Join Date
    Jun 2012
    Posts
    54

    Re: how to use http mutipart/form data wiki example to upload a image

    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

  11. #11
    Nokia Developer Champion
    Join Date
    Nov 2011
    Location
    India
    Posts
    360

    Re: how to use http mutipart/form data wiki example to upload a image

    Quote Originally Posted by preety.saini View Post
    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

    Can you paste some code here depicting the cause?

  12. #12
    Registered User
    Join Date
    Jun 2012
    Posts
    54

    Re: how to use http mutipart/form data wiki example to upload a image

    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"));
    }

  13. #13
    Registered User
    Join Date
    Jun 2012
    Posts
    54

    Re: how to use http mutipart/form data wiki example to upload a image

    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.

  14. #14
    Nokia Developer Champion
    Join Date
    Nov 2011
    Location
    India
    Posts
    360

    Re: how to use http mutipart/form data wiki example to upload a image

    so you are talking about these lines:
    Code:
    RStringF method;
    TRAPD(err1, method = iSession.StringPool().StringF(HTTP::EPOST,RHTTPSession::GetTable()));
    Have you checked iSession here? Is it NULL or not?

  15. #15
    Registered User
    Join Date
    Jun 2012
    Posts
    54

    Re: how to use http mutipart/form data wiki example to upload a image

    I checked iSession value,it's not NULL

Page 1 of 2 12 LastLast

Similar Threads

  1. How to post/upload image as a content data of form
    By bnpawar in forum Symbian C++
    Replies: 0
    Last Post: 2009-11-13, 11:15
  2. How to upload Image form FTP
    By pranay_preet in forum Symbian Networking & Messaging (Closed)
    Replies: 6
    Last Post: 2009-08-10, 09:08
  3. How to upload a long video as a binary file to a server as Multipart/form-data
    By MForceOne in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2009-07-31, 16:24
  4. Image Upload - multipart/form-data
    By thiagobrunoms in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2008-02-20, 12:07
  5. Image upload form
    By jarips in forum Browsing and Mark-ups
    Replies: 13
    Last Post: 2004-01-19, 14:40

Posting Permissions

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