Hi!
Is possible to download a picture with Sparkle client?
I tried this code, but gives me "JPEG error 42"
procedure GetCusomImage(Url: string; Pic: TPicture);
var
Client: THttpClient;
Request: THttpRequest;
Response: THttpResponse;
ResponseBody: string;
stream: TMemoryStream;
lPNG: TPngImage;
lJPEG: TJPEGImage;
begin
try
Client := THttpClient.Create;
Log(llInfo, 'Gettings orders list from URL: '+Url);
Request := Client.CreateRequest;
Request.Uri := Url;
Request.Method := 'GET';
Request.SetContent(TEncoding.UTF8.GetBytes('Request content'));
Response := Client.Send(Request);
if Response.StatusCode = 200 then begin
stream := TMemoryStream(Response.ContentAsStream);
stream.Position := 0;
if Url.EndsWith('.jpg') or Url.EndsWith('.jpeg') then begin
lJPEG := TJPEGImage.Create;
try
lJPEG.LoadFromStream(stream);
Pic.Assign(lJPEG); <---------------- Error here
finally
lJPEG.Free;
end;
end;
end else begin
Log(llError, 'URL call failed: '+IntToStr(Response.StatusCode));
end;
finally
Request.Free;
Response.Free;
Client.Free;
end;
end;
What am I doing wrong?