mormot multipart/form-data
uses SynCommons;
function upload(mimetype, params: string): string;
var
parts: TMultiPartDynArray;
i: Integer;
filename:string;
ss: tstringstream;
ms: tmemorystream;
begin
MultiPartFormDataDecode(mimetype, params, parts);
for i:=0 to high(parts) do
begin
if sametext(parts[i].Name, 'filename') then
begin
filename:=parts[i].Content;
end;
if sametext(parts[i].Name, 'file') then
begin
ss:= tstringstream.Create(parts[i].Content);
ms:=tmemorystream.Create;
ms.Size := ss.Size;
ms.CopyFrom(ss, ss.Size);
ms.SaveToFile('c:\1.exe');
ss.Free;
ms.Free;
end;
end;
end;
调用演示:
restfunc.upload(ctxt.InContentType, ctxt.InContent);
