FPHttpServer provide .png files lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- anderbelluno · 2023-04-07 13:56 Hey guys. I need to provide .png files using FPHTTPServer, I can't find much on the subject. I'm studying the possibilities, to later improve the codes. Note: these are tests. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i class procedure TLib.LoadImg(var aStream: TMemoryStream);var   xFile : TMemoryStream;begin   xFile := nil;   xFile := TMemoryStream.Create;   try     xFile.LoadFromFile('C:\Users\anderson\Desktop\Lazarus\FPHTTP\ Server\img.png');     xFile.Position:=0;     xFile.SaveToStream(aStream);   finally     FreeAndNil(xFile);   end; end; This procedure reads the file... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FPHttpServer1Request(Sender: TObject;   var ARequest: TFPHTTPConnectionRequest;   var AResponse: TFPHTTPConnectionResponse);var   xStream: TMemoryStream;begin       xStream := TMemoryStream.Create;       try        TLib.LoadImg(xStream);        xStream.Position:= 0;        xStream.SaveToStream(AResponse.ContentStream);        AResponse.ContentType:='image/png'; //; charset=utf-8       finally       FreeAndNil(xStream);       end;end; This is the FPHTTPServer's onRequest. But the image that is returned is not correct. What am I doing wrong? Thanks. ---------------------------------------------------------------------- Leledumbo · 2023-04-07 15:32 Though I don't know why you want to reinvent the wheel, you can take a look at how it's done. ---------------------------------------------------------------------- anderbelluno · 2023-04-07 20:05 Excuse my ignorance my friend, I never wanted to reinvent the wheel, I'm simply learning to use the component, so I'm making mistakes and learning. Thanks a lot for your help, it worked great.