Try something more like this:
//Server
function TServerMethods1.DownloadImage(xUrlImg : String; out resp : String) : TStream;
var
HTTP : TIdHttp;
Stream : TStream;
Bmp : TBitmap;
Fmt: TFormatSettings;
begin
Result := nil;
try
Stream := TMemoryStream.Create;
try
HTTP := TIdHttp.Create(nil);
try
HTTP.ReadTimeout := 10000;
HTTP.ConnectTimeout := 10000;
HTTP.Get(xUrlImg, Stream);
finally
HTTP.Free;
end;
Bmp := TBitmap.Create(0, 0);
try
Stream.Position := 0;
Bmp.LoadFromStream(Stream);
Fmt := TFormatSettings.Create;
Fmt.DateSeparator := #0;
Fmt.TimeSeparator := #0;
Bmp.SaveToFile('C:\SISTEMAS\MOBILE\' + DateTimeToStr(Now, Fmt) + '.jpg');
Stream.Clear;
Bmp.SaveToStream(Stream);
Stream.Position := 0;
finally
Bmp.Free;
end
except
Stream.Free;
raise;
end;
Result := Stream;
except
on E: Exception do
begin
resp := 'ERRO: ' + E.Message;
end;
end;
end;
//client
function TFPrin.SalvaImg(URL, xNomeImg : String) : Boolean;
var
Stream : TStream;
Bmp : TBitmap;
sTemp : String;
begin
try
Stream := ClientModule1.ServerMethods1Client.DownloadImage(URL, sTemp);
if Stream = nil then
begin
ShowMessage('Erro: ' + sTemp);
Exit;
end;
try
Bmp := TBitmap.Create(0, 0);
try
Bmp.LoadFromStream(Stream);
Bmp.SaveToFile(GetDirPlat + xNomeImg);
finally
Bmp.Free;
end;
finally
Stream.Free;
end;
except
on E: Exception do
begin
ShowMessage('Erro gerar imagem: ' + e.Message);
end;
end;
end;