How to upload files to server with chunks

Login to reply to this topic.
Fri, 2008-03-28 10:48
Joined: 2008-03-28
Forum posts: 2

Hi, everyone, I want to upload a large file to server, and i use http post to upload, here is my code segment:

TInt CHttpXXX::SetHeader( )
{
        if(iPostData==NULL)
        {
                iPostData = HBufC8::NewL(10000);
        }
        iStart = -1;

        TPtr8 iPostDataPtr = iPostData->Des();
        iPostDataPtr.Zero();
        iPostDataPtr.Append(_L("--AaB03x"));
        iPostDataPtr.Append(_L("\r\n"));
        iPostDataPtr.Append(_L("Content-Disposition: form-data; name=\"name\""));
        iPostDataPtr.Append(_L("\r\n\r\n"));
        iPostDataPtr.Append(_L("xxxxxxxxxxxxxxxx"));
        iPostDataPtr.Append(_L("\r\n"));
       
        iPostDataPtr.Append(_L("--AaB03x"));
        iPostDataPtr.Append(_L("\r\n"));
        iPostDataPtr.Append(_L("Content-Disposition: form-data; name=\"password\""));
        iPostDataPtr.Append(_L("\r\n\r\n"));

        iPostDataPtr.Append(_L("yyyyyyyyyyyyyyyy"));
        iPostDataPtr.Append(_L("\r\n"));

        iPostDataPtr.Append(_L("--AaB03x"));
        iPostDataPtr.Append(_L("\r\n"));
        iPostDataPtr.Append(_L("Content-Disposition: form-data; name=\"file\"; filename=\"xxx.png\""));
        iPostDataPtr.Append(_L("\r\n"));

        iPostDataPtr.Append(_L("Content-Type: image/png"));
        iPostDataPtr.Append(_L("\r\n\r\n"));

                TInt fileSize = GetFileSize(_L("C:\\DATA\\hello.png")); // this function I wrote for geting the file's size

        iDataLength = iPostDataPtr.Length() + fileSize;
        TBuf<50> buf(0);
        buf.Copy(_L("\r\n"));
        buf.Append(_L("--AaB03x"));
        buf.Append(_L("--"));

        iDataLength += buf.Length();

        return 0;
}

TBool CHttpXXX::GetNextDataPart(TPtrC8& aDataPart)
{
        if(iStart == -1)
        {
                aDataPart.Set(iPostData->Des());
                iDataAvailable = ETrue;
                iStart = 0;
                return EFalse;
        }

        TPtr8 ptr = iPostData->Des();
        if(iStart<=GetFileSize(_L("C:\\DATA\\hello.png")))
        {
                ptr.Zero();
                TBuf8<6000>* temp = new(ELeave) TBuf8<6000>(0);
                CleanupStack::PushL(temp);
                LoadPartFileDataToBuffer(_L("C:\\DATA\\hello.png"), *temp, iStart, 5*1024);// this function is used for load a part data of the file, the last two parms is stand for the start index and the length
                ptr.Copy(*temp);
                iStart += 5*1024;
                aDataPart.Set(iPostData->Des());
                iDataAvailable = ETrue;
                iPartFinished = EFalse;
                CleanupStack::PopAndDestroy(temp);
                return EFalse;
        }
        else
        {
                ptr.Zero();
                ptr.Copy(_L("\r\n"));
                ptr.Append(_L("--AaB03x"));
                ptr.Append(_L("--"));
                aDataPart.Set(iPostData->Des());
                iDataAvailable = EFalse;
                return ETrue;
        }

}

void CHttpXXX::ReleaseData()
{
        if(iDataAvailable)
        {
                iTransaction.NotifyNewRequestBodyPartL();
        }
}

TInt CHttpXXX::Reset()
{
        return 0;
}

TInt CHttpXXX::OverallDataSize()
{
        if(iPostData)               
            return iDataLength;
        else
            return KErrNotFound;

}

The code works on symbian 8.1a SDK, but just only work on emulator but can not work on 6680, when
I upload a file, the screen has no response. And in symbian9.1 SDK, it can not work on emulator and device, Idon't know which part is wrong, can anybody help me? Thanks verymuch


Tue, 2008-04-01 08:16
NewLC AdministratorSymbian AccreditedForum Nokia Champion
Joined: 2003-01-14
Forum posts: 1918
Re: Hi, can anyone help me to solve this emergency problem?

1) Put a better title at your thread
2) be more descriptive. What doesn't works ? What happens ? Panic ? Error code ? Just nothing ?
3) That's really weird code: TBuf8<6000>* temp = new(ELeave) TBuf8<6000>(0);


Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant

Tue, 2008-04-01 09:39
Forum Nokia Champion
Joined: 2006-10-12
Forum posts: 463
Re: Hi, can anyone help me to solve this emergency problem?

Kimnan,

Welcome to the Forum!!

just to add to Eric's suggestion, remember developers help each other not out of force but voluntarily. Pasting almost the whole project without really telling about the problem is torturing them really. You wouldnt want to do it to somebody who wants to help you.
Second..everybody has a deadline and hence every task is 'emergency'. The thread title is to indicate about the thread, so that if you know about you read furthur, else skip the thread. So please help the readers with that one.

Thanks

Wed, 2008-04-02 02:24
Joined: 2008-03-28
Forum posts: 2
Re: How to upload files to server with chunks

hi, eric, there is no panic or error code, just there is no any response

  • Login to reply to this topic.