I use a web site that requires a logon and at one point shows a jpg using the http

```
<img src="https://www.theurl.com/pictures/Photo.ashx?theid=221">

```

I want to use Delphi to download this image (and others by using a different parameter) and store it in a SQLite database.

I am able to take a jpg file from my HDD and store it in the database with..

```
procedure TForm1.Button1Click(Sender: TObject);  //this works
begin
DISQLite3Database1.DatabaseName := 'C:\testphoto.db';
DISQLite3Database1.Open;
try
  Query1.Close;
  Query1.selectSQL := ('insert into StudentPhotos(id,photo) 
                        values(''sally'', :photo)');
  Query1.Params.ParamByName('photo').LoadFromFile
                         ('C:\Users\Admin\Documents\testpic2.jpg',ftGraphic);
Query1.Open ;
finally
  DISQLite3Database1.close;
end;
end;

```

I am also able to download the image from the website into a file using the following (after running code that handles the logon)

```
procedure TForm1.Button2Click(Sender: TObject);
var
  Strm: TMemoryStream;
  HTTP: TIdHTTP;
  LHandler: TIdSSLIOHandlerSocketOpenSSL;

begin
try
   http:=  TIdHTTP.create;  //make an http component
   LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
   Strm := TMemoryStream.Create;
   HTTP.IOHandler:=LHandler;
   HTTP.HandleRedirects := true;   
   HTTP.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';     try
     Http.Get('https://www.TheUrl.com/picures/Photo.ashx?theid=221' , Strm);
     Strm.Position := 0;
     Strm.SaveToFile('C:\Users\Admin\Documents\testpic2.jpg');
     except
     on e:Exception do
        begin
        ShowMessage(E.ClassName+' error raised, with message : '+E.Message);
          showmessage('could not download file');
          end;
        end;

   finally
      http.Free;
      LHandler.Free  ;
      Strm.free; 
   end;
end;

```

However I'd prefer not to save each file on the clients hard drive and then read it back in to save it into the database as that will be quite slow.

**Question**

What is the correct syntax to combine both of the above procedures so that I can download into a stream and then pass the stream directly into the query parameter ready to save it in the database?

Note I am using DISQLIte3 but the query methods/properties are similar to other components.