Solved

Loading a file into memory from a URL

Posted on 2003-11-28
4
687 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:mnasman
mnasman 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now