Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Download file to memory?

Posted on 2008-10-23
8
Medium Priority
?
291 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
[X]
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
  • 4
  • 4
8 Comments
 
LVL 38

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 38

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

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

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 38

Accepted Solution

by:
Geert Gruwez earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

715 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