Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Download file to memory?

Posted on 2008-10-23
8
288 Views
Last Modified: 2013-11-23
Hi Experts,
Someone can help me to download a file (any file on webs) to the memory (stream or somthing)?

thanks :)
0
Comment
Question by:controlr
  • 4
  • 4
8 Comments
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 22784458
procedure TForm1.GetFileFromWeb;
var astream: TMemoryStream;
  aFile: string;
begin
  aStream := TMemoryStream.Create;
  try
    idHttp1:=TIdHTTP.Create(self);
    try
      aFile := 'http://www.google.com';
      idHttp1.Get(Site, aStream);
    finally
      idHttp1.Free;
    end;
    // do something with the stream
  finally
    aStream.Free;
  end;
end;  
0
 

Author Comment

by:controlr
ID: 22784903

thats look good
but why i cant load the stream to an Timage?

example:
aFile := 'http://www.makav.co.il/logo.bmp';
  Image1.Picture.Bitmap.LoadFromStream(astream);

thanks for helping
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 22784919
is there a bitmap in the picture before you load it ?

load a bitmap in the picture first with the ide
I can't be anything, like a white bitmap of 1x1 square

then try again
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:controlr
ID: 22784967
i tried that allready and it does not work :(
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 22784973
does loading the file from the website work ?
0
 

Author Comment

by:controlr
ID: 22784991
i think yes because when i save it to file i see the image.
but i want to save it to stream and then to load it directly to the timage without using the disk
0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 22785088
i can't test the Get function here as i am behind a firewall,
i'll test the other stuff

you need to set the stream to the beginning




procedure TForm1.GetFileFromWeb;
var astream: TMemoryStream;
  aFile: string;
begin
  aStream := TMemoryStream.Create;
  try
    idHttp1:=TIdHTTP.Create(self);
    try
      aFile := 'http://www.google.com';
      idHttp1.Get(Site, aStream);
    finally
      idHttp1.Free;
    end;
    aStream.Seek(soFromBeginning, 0);
    Image1.Picture.Bitmap.LoadFromStream(aStream);
  finally
    aStream.Free;
  end;
end;  

Open in new window

0
 

Author Comment

by:controlr
ID: 22785122
thanks a lot man!!!!
its working
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question