mORMot怎么实现文件上传?

laimama1000

Registered
Registered
注册
2015-06-15
消息
1
看DEMO 09实现了文件下载,但是不知道怎么实现文件上传,高手给点提示!!
 
上传数据格式必须是:MULTIPART/FORM-DATA
后端处理参照下列代码:
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;
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;
 
后退
顶部