简体   繁体   中英

Delphi XE2 Firemonkey File Download?

How can i download a file over a url in firemonkey that is compatible in both Windows and MacOS X? the download should be over https.

The Indy that's supplied with XE2 supports Mac OSX.
See: Does Delphi XE2 FireMonkey support Indy for cross-platform apps?

Here's the workflow:

File-> New (Firemonkey HD app)
Add Mac OSX as target platform
Place a TIdHTTP component on the form
Place a TEdit on the form

The following code should get some rudimentary results

type
  TForm16 = class(TForm)
    IdHTTP1: TIdHTTP;
    Edit1: TEdit;
    procedure Edit1Enter(Sender: TObject);
  public
    MyFile: TFileStream;
  end;

implementation

{$R *.fmx}

procedure TForm16.Edit1Enter(Sender: TObject);
var
  Success: boolean;
begin
  if (MyFile = nil) then try
    //Correct path handling to be added
    //filename should be extracted from the url etc etc.
    MyFile:= TFileStream.Create('Test.dat',fmCreate);
    Success:= true;
  except
    Success:= false;
  end;
  if Success then begin
    IdHTTP1.Get(Edit1.Text, MyFile);
    //do stuff with the file
  end;
end;

One word of advise, make sure it works with http first, https can be tricky to setup.
Also make sure you have the latest version of Indy installed and the latest XE2 updates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM