2015-09-02 74 views
1

我寫的程序,從谷歌下載文件驅動器:RestRequest下載文件德爾福XE7

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的或內存流,讓我的文件,是有可能或者我應該使用idhttp做到這一點?

回答

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;