RestRequest下载文件delphi xe7

时间:2015-09-02 09:15:01

标签: delphi google-drive-api

我已经编写了从google drive下载文件的程序:

procedure DownloadfromDriveMyGolden2File;
begin

  form2.RESTResponseDataSetAdapter1.AutoUpdate := false;
  form2.RESTRequest1.Params.Clear;
  form2.RESTRequest1.ClearBody;
  form2.RESTRequest1.Method:=rmget;
  Form2.RESTClient1.BaseURL:='https://www.googleapis.com/drive/v2/files/{FileId}?alt=media';
  form2.RESTRequest1.Resource := '';
  form2.RESTRequest1.Params.AddUrlSegment('FileId', form2.Edit4.Text);
try
  form2.RESTRequest1.Execute;
except
on e: Exception do
begin
  ShowMessage(e.Message);//Show Exception
end;
end;
end;

但我无法想象我可以捕获Tfilestream或Tmemorystream来获取我的文件,是否可以或我应该使用idhttp来执行此操作?

1 个答案:

答案 0 :(得分:1)

我找到了答案:

 procedure ServerResponseToFile;
var
  SomeStream : tmemorystream;
  local_filename : string;
begin
//в андроиде обратные слеши
 {$IF DEFINED(MsWindows)}
  local_filename :=  ExtractFilePath(ParamStr(0))     +'syncdownload/Northwindpers.sqlite3';
 {$ENDIF}
  SomeStream := tmemorystream.Create;
  Somestream.WriteData(form2.RESTResponse1.RawBytes,Length(form2.RESTResponse1.Raw  Bytes));
  SomeStream.SaveToFile(local_filename);
  SomeStream.free;
end;