Reputation: 535
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.
Upvotes: 2
Views: 3237
Reputation: 76753
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.
Upvotes: 3