开发学院手机开发Symbian 开发 Symbian C++ Multipart/form-data 阅读

Symbian C++ Multipart/form-data

 2010-09-16 00:02:00 来源:WEB开发网   
核心提示:The following code can be used to upload any file, image, text , video etc.. as a binary file to a server.The HTTPEngine should have MHTTPDataSupplier as its pa

The following code can be used to upload any file, image, text , video etc.. as a binary file to a server.

The HTTPEngine should have MHTTPDataSupplier as its parent class, as the following functions need to be implemented for the upload process

TBool GetNextDataPart(TPtrC8& aDataPart);void ReleaseData();TInt Reset();TInt OverallDataSize();

The content-type for the post should be

_LIT8(KPostContentType, "multipart/form-data; boundary=AaB03x");

In the MHFRunL the case EGotResponseBodyData should do this

MHTTPDataSupplier* dataSupplier = aTransaction.Response().Body();TPtrC8 ptr;dataSupplier->GetNextDataPart(ptr); // Convert to 16-bit descriptorHBufC* buf = HBufC::NewLC(ptr.Length());buf->Des().Copy(ptr); // Append to iResponseBufferif (iResponseBuffer==NULL){iResponseBuffer = buf->AllocL();}else{iResponseBuffer = iResponseBuffer->ReAllocL(iResponseBuffer->Length()+buf->Length());iResponseBuffer->Des().Append(*buf);} // Release bufCleanupStack::PopAndDestroy(buf); if(!iDataAvailable){ iRunning=EFalse; iTransaction.Close(); } else{ dataSupplier->ReleaseData();}

POST code Get the file you want to upload in binary format

RFs aFs;User::LeaveIfError(aFs.Connect());CleanupClosePushL(aFs); RFile aFile; User::LeaveIfError(aFile.Open(aFs, iFileName, EFileShareAny)); TInt aSize;User::LeaveIfError(aFile.Size(aSize)); iPostDataImage = HBufC8::NewL(aSize);TPtr8 aPtr = iPostDataImage->Des(); //Obviously we have to read in the data to the iPostDataImage (ray)aFile.Read(0, aPtr, aSize); aFile.Close();aFs.Close();CleanupStack::PopAndDestroy(&aFs);

Using EFileShareAny ensures that if the file can be opened by any other application. The file is read into iPostDataImage as a binary file.

Now create the upload format

_LIT8(KDataStart,"--AaB03x");_LIT8(KCrlf," ");_LIT8(KContent,"Content-Disposition:

1 2  下一页

Tags:Symbian Multipart form

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接