MORMOT REST文件上传

MORMOT REST文件上传

上传数据格式必须是:MULTIPART/FORM-DATA

uses SynCommons

后端处理参照下列代码:

后端处理参照下列代码:
procedure TWebEnv.processMultiPartFormData;
var
i: Integer;
cFileName, cName, cValue: string;
mp: TMultiPart;
begin
MultiPartFormDataDecode(FContext.InContentType, FContext.InContent, FMultiPartFields);
for i := Low(FMultiPartFields) to High(FMultiPartFields) do begin
mp := FMultiPartFields[i];
cFileName := Server.SaveUpload(mp);
cName := UTF8ToString(mp.Name);
if Length(cFileName) > 0 then begin
cValue := FContentFields.Values[cName];
if Length(cValue) > 0 then cValue := cValue + ',';
cValue := cValue + cFileName;
FContentFields.Values[cName] := cValue;
FMultiPartFields.FileName := StringToUTF8(cFileName);
end
else FContentFields.Values[cName] := UTF8ToString(StringReplaceAll(mp.Content, #13#10, '\n'));
end;
end;

  

posted @ 2019-12-18 16:18  delphi中间件  阅读(1366)  评论(0编辑  收藏  举报