Solved

Loading a file into memory from a URL

Posted on 2003-11-28
4
703 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
[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 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

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

705 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