Discuss this help topic in SecureBlackbox Forum

HTTPS: Handle multipart requests

The client can post a multipart request (eg. form data) to the server. The server should inspect the value of Content-Type request header and if the value is "multipart/form-data", then the procedure described below can be applied to handle such data.

Once you have all the data, call TElHTTPSServer.ParseMultipartFormData() method and pass it the received data. The method returns an instance of TElMultipartFormList class, which can then be used to access fields of the form that has been posted. TElMultipartFormList class has ValuesBy* properties, which return instances of TElMultipartFormData class, each instance representing a field in the form. You can inspect various properties of TElMultipartFormData instance to find out, what exactly is contained in the element (i.e. is this a form field or an attached file) get the size of the element etc.



TElHTTPSServer m_httpsServ = new TElHTTPSServer();
MemoryStream ms = new MemoryStream();
TElHTTPServerRequestParams currentRequest = ...; // current request object

// parse data
TElMultipartFormList mpl = m_httpsServ.ParseMultipartFormData(currentRequest, ms, true); // ms contains collected incoming data

TElMultipartFormData param1 = mpl.GetValuesByName("param1"); // read request parameter named "param1"
byte[] value1 = param1.GetContent(); // get its value

// if we have a file in request
TElMultipartFormData file = mpl.GetValuesByName("myfile"); // read POST parameter named "myfile"
if (file != null)
	string fileName = file.GetName(); // get file name
	byte[] value2 = new byte[file.GetContentSize()]; // allocate buffer for file content
	Array.Copy(file.GetBuffer(), file.GetContentStartPos(), value2, 0, file.GetContentSize()); // copy file content to buffer

How To articles about server-side HTTPS questions

Discuss this help topic in SecureBlackbox Forum