How to upload a long video as a binary file to a server as Multipart/form-data
Hi,
I try to upload a video file from a Nokia 5800.
I am writing my code based on [url]http://wiki.forum.nokia.com/index.php/Symbian_C++_:_Multipart/form-data[/url].
My problem is that I have a big video file (e.g. 45MB) and when I try to create a buffer for the file a panic exception occurs.
I guess it is not possible to create such a big buffer in memory.
TFileName fileName;
RFile iReqBodyFile;
fileName.Copy(mFilePath);
if (iFileServ.IsValidName(fileName)) {
[INDENT]TInt iRetVal = iReqBodyFile.Open(iFileServ, mFilePath , EFileRead);
if (KErrNone != iRetVal){
[INDENT]return EFalse;[/INDENT]
}
TInt ourFilesize = 0;
User::LeaveIfError(iReqBodyFile.Size(ourFilesize));
[B]iReqBodySubmitBuffer = HBufC8::NewL(ourFilesize); // panic exception happens here[/B]
TPtr8 aPtr= iReqBodySubmitBuffer->Des();
TInt readerr = iReqBodyFile.Read(0,aPtr,ourFilesize);
if (readerr != KErrNone){
[INDENT]return EFalse;[/INDENT]
}
iReqBodySubmitBuffer1 = NULL;
iReqBodySubmitBuffer1 = HBufC8::NewL(xmlPtr.Length()+ending.Size()+aPtr.Length());
TPtr8 iPostDataPtr = iReqBodySubmitBuffer1->Des();
iPostDataPtr.Zero();
iPostDataPtr.Append(xmlPtr); // some xml data
iPostDataPtr.Append(aPtr);
iPostDataPtr.Append(ending);[/INDENT]
}
I debugged the code with Carbide.C++ v2.0 direct on the Nokia device.
The debug exception output is:
Signal 'Exception 100' received. Description: Thread 0x1ec has panicked. Category: E32USER-CBase; Reason: 47.
Can somebody help me how to send a Multipart/form-data HTTP Post request with a large file?
What needs to be done different?
Thank you very much for your help
Mirko
Re: How to upload a long video as a binary file to a server as Multipart/form-data
the error is "This panic is raised by the Error() virtual member function of an active scheduler, a CActiveScheduler. This function is called when an active object’s RunL() function leaves. Applications always replace the Error() function in a class derived from CActiveScheduler; the default behaviour provided by CActiveScheduler raises this panic. "
So you should actually check what the original leave in RunL was, anyway, I belaive that you can use MHTTPDataSupplier to supply the data in parts for the post sending.
Re: How to upload a long video as a binary file to a server as Multipart/form-data
Hi symbianyucca,
thank you for the response.
In your response you said " I believe that you can use MHTTPDataSupplier to supply the data in parts for the post sending."
Could you explain it in more details how i can assemble the post body part which contains a big file and send it with HTTP Post (Multipart/form-data) but transmit the body in chunks?
Thank you for your help.
Mirko
Re: How to upload a long video as a binary file to a server as Multipart/form-data
I suppose GetNextDataPart gets called by the HTTP API and if you tell in there that it is not the last part, then it will be called again, thus you can supply the data in smaller parts..
Re: How to upload a long video as a binary file to a server as Multipart/form-data
Ok,
I understand that.
That would mean to me if i have to send a post body like this:
[INDENT]--<boundary_string>
Content-Type: application/atom+xml; charset=UTF-8
API_XML_request
--<boundary_string>
Content-Type: <video_content_type>
Content-Transfer-Encoding: binary
[B]<Binary File Data>[/B]
--<boundary_string>--[/INDENT]
I would have some logic in GetNextDataPart which takes care of sending the data in 3 steps:
1. Sending all post data prior to the binary file data.
[INDENT]--<boundary_string>
Content-Type: application/atom+xml; charset=UTF-8
API_XML_request
--<boundary_string>
Content-Type: <video_content_type>
Content-Transfer-Encoding: binary[/INDENT]
2. Sending the binary file data in chunks which each more GetNextDataPart call.
[INDENT]<Binary File Data>[/INDENT]
3. If all binary data is send continue by sending the closing boundary string.
[INDENT]--<boundary_string>--[/INDENT]
What do you think about that approach?
Mirko