mormot multipart/form-data

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);

 

posted @   delphi中间件  阅读(865)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示