概述
rest api上传和下载文件
function FileToString(AFileName: string): string;
var
LMemoryStream: TMemoryStream;
LStringStream: TStringStream;
LDstStream: TMemoryStream;
begin
Result := '';
if not FileExists(AFileName) then
Exit;
LMemoryStream := TMemoryStream.Create;
LStringStream := TStringStream.Create;
LDstStream := TMemoryStream.Create;
try
LMemoryStream.LoadFromFile(ExtractFilePath(ParamStr(0)) + AFileName);
LMemoryStream.Position := 0;
ZCompressStream(LMemoryStream, LDstStream);
LDstStream.Position := 0;
TNetEncoding.Base64.Encode(LDstStream, LStringStream);
Result := LStringStream.DataString;
finally
LMemoryStream.Free;
LStringStream.Free;
LDstStream.Free;
end;
end;
procedure FileFromString(AFileName, AFileContent: string);
var
LStringStream: TStringStream;
LMemoryStream: TMemoryStream;
LOrgStream: TMemoryStream;
begin
if AFileName = '' then
Exit;
LStringStream := TStringStream.Create(AFileContent);
LMemoryStream := TMemoryStream.Create;
LOrgStream := TMemoryStream.Create;
try
LStringStream.Position := 0;
TNetEncoding.Base64.Decode(LStringStream, LOrgStream);
LOrgStream.Position := 0;
ZDecompressStream(LOrgStream, LMemoryStream);
LMemoryStream.Position := 0;
LMemoryStream.SaveToFile(ExtractFileName(AFileName));
finally
LStringStream.Free;
LMemoryStream.Free;
LOrgStream.Free;
end;
end;
转载于:https://www.cnblogs.com/hnxxcxg/p/10272284.html
最后
以上就是自觉绿茶为你收集整理的rest api上传和下载文件的全部内容,希望文章能够帮你解决rest api上传和下载文件所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复