Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Loading a file into memory from a URL

Posted on 2003-11-28
4
Medium Priority
?
708 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 100 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 500 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 1400 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

618 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