Unit
ScHttpMultipartData
Description
The TScHttpServerMultipartDataList class is designed for use with TScHttpRequestInfo and implements reading and parsing of its InputStream property in the multipart/form-data format, as defined in RFC 7578. Since the TScHttpRequestInfo object is passed as a parameter to the TScHttpServer.OnProcessRequest event, it should also be processed within that event.
This following example shows how to parse TScHttpRequestInfo.InputStream into the Parts list and save the data parts as separate files.
Parts := TScHttpServerMultipartDataList.Create(RequestInfo);
try
Parts.ParseStream;
for i := 0 to Parts.Count - 1 do
if Parts[i].FileName <> '' then begin
FileStream := TFileStream.Create(AttDir + Parts[i].FileName, fmCreate);
try
RequestInfo.InputStream.Position := Parts[i].Start;
FileStream.CopyFrom(RequestInfo.InputStream, Parts[i].Size);
finally
FileStream.Free;
end;
end;
finally
Parts.Free;
end;
Check also the example in the Demos\HttpServer\ directory.
See also