Am looking for a way to download a image from a URL using twebbrower and to save it to a folder, it would access url and then have section for file name and folder name and then it would save the file as a jpg to the folder on drive.

I googled this and I can not seam to find what I need so am wondering if anyone can help ?

Thanks

Code am using is as following it downloads file and puts into directory but the file it self is not downloaded correctly its incorrect size and it dont open anyone got any ideas cheers

  MS := TMemoryStream.Create;
  try
    Http.Get(URL, MS);
    MS.SaveToFile(FileDir + FileName);
  finally
    MS.Free;
  end;
function DownloadFile(URL : string; FileName : string) : boolean;
var
  IdHTTP: TIdHTTP;
  FileStream : TFileStream;
begin
  try
    IdHTTP := TIdHTTP.Create(nil);
    try
      FileStream := TFileStream.Create(FileName, fmCreate);
      try
        IdHTTP.Get(URL, FileStream);
      finally
        FileStream.Free;
      end;
      Result := TRUE;
    finally
      IdHTTP.Free;
    end;
  except
    Result := FALSE;
  end;
end;

Thanks but still the same out come everytime I download the image it not downloaed correctly

The Filesize should be 4.30 KB (4,412 bytes) but the
Filesize I get is 948 bytes (948 bytes) I tried few code none seams to work..

That is odd. I haven't had any issues with that code. What is the URL for the file you want?

Interesting. It works fine here. I nade a simple test app with a web browser, and edit box, and a button. The code I used was as I posted above plus:

procedure TForm2.Button1Click(Sender: TObject);
begin
  if DownloadFile(Edit1.Text, 'C:\Users\MyName\Documents\Test.JPG') then
    WebBrowser1.Navigate('C:\Users\MyName\Documents\Test.JPG');
end;

I put
http://www.team-mplayer.net/portraits/02002/00002.jpg
in the edit box, clicked the button, and the image appeared correctly in the web browser. Can you try that?

I worked it out I was not putting the file name on the URL silly me thanks for the help salmi :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.