Solved

Loading a file into memory from a URL

Posted on 2003-11-28
4
696 Views
Last Modified: 2013-11-18
I have created an ActiveX plugin for Internet Explorer for viewing Tiff files.
I can view Tiff Files with filename like "\\Servername\Images\image.tif", but what I would like to do is view tiff files with filename like "http://www.webserver.co.uk/images/image.tiff".

The solution I'm looking for, is where the Tiff file is loaded straight into a TMemoryStream from the webserver.
0
Comment
Question by:StayGreedy
4 Comments
 
LVL 5

Assisted Solution

by:DeerBear
DeerBear earned 25 total points
ID: 9836960
Hi,

Use IdHTTP1.Get from Indy, you can pass a buffer stream as parameter and it should work.

HTH,

Andrew
0
 
LVL 22

Assisted Solution

by:Mohammed Nasman
Mohammed Nasman earned 125 total points
ID: 9837255
Something like that

procedure TForm1.Button1Click(Sender: TObject);
var
  ImgPath : string;
  MS : TMemoryStream;
begin
  ImgPath := 'http://www.experts-exchange.com/images/logo.gif';
  MS := TMemoryStream.Create;
  idHttp1.Get(ImgPath,MS);
// if u don't want to save the img to harddisk remove this line
  MS.SaveToFile('c:\img.gif');
  MS.Free;
end;
0
 
LVL 9

Accepted Solution

by:
mocarts earned 350 total points
ID: 9837400
hi
there is also possible to use wininet.pas unit provided with delphi (no need for install Indy, just copy in your sorce and use):

uses wininet;

function GetStreamFromURL(const aURL: string; aStream: TStream): boolean;
const
  lBufSize = 4096;
var
  hi, hu: HINTERNET;
  buf: array [1..lBufSize] of byte;
  dwcb: dword;
begin
  Result := False;
  aStream.Size := 0;
  hi := internetOpen('StreamFromURL', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  if assigned(hi) then
  try
    hu := internetOpenURL(hi, PChar(aURL), nil, 0, INTERNET_FLAG_KEEP_CONNECTION, 0);
    if assigned(hu) then
    try
      repeat
        Result := internetReadFile(hu, pointer(@buf), lBufSize, dwcb);
        if Result then
          aStream.Write(buf, dwcb);
      until not Result or (dwcb <> lBufSize);
    finally
      internetCloseHandle(hu);
    end;
  finally
    internetCloseHandle(hi);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  fs: TMemoryStream;
begin
  fs := TMemoryStream.Create;
  try
    if GetStreamFromURL('http://home.fortech.lv/~helmuts/delphi/PalmDB.zip', fs) then
    begin
      fs.SaveToFile('D:\PalmDB.zip');
      Caption := 'ok';
    end;
  finally
    fs.Free;
  end;
end;

wbr, mo.
0
 
LVL 1

Author Comment

by:StayGreedy
ID: 9837549
Thanks to DeerBear for idea of using the indy component.
Thanks to mnasman for the indy example
Special thanks to mocarts for the alternative example, the one I am using :)

Cheers.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 221
Delphi cmd execution 6 62
can't find the executable in Simulator 1 95
Delphi Yen format 3 35
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
I made this because I wanted to get e-mail with a attached csv file so I'd would be able to import user input into a MS Excel template, but I also wanted to register/save all inputs from each day in a file on the server. 1st - It creates a temp C…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

825 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