andyhill Posted November 23, 2018 Share Posted November 23, 2018 Please advise how UniGUI to upload to dropbox (can incorporate CallBack for success/failure):- 1) Using OAuth2 (user interaction) 2) Using Token (no user interaction) Thanks in advance (* DFM object RESTClient1: TRESTClient Authenticator = OAuth2Authenticator1 Params = <> HandleRedirects = True Left = 32 Top = 440 end object RESTRequest1: TRESTRequest Client = RESTClient1 Params = <> Response = RESTResponse1 SynchronizedEvents = False Left = 104 Top = 440 end object RESTResponse1: TRESTResponse Left = 192 Top = 440 end object OAuth2Authenticator1: TOAuth2Authenticator AccessToken = 'mytoken' ClientID = 'myclientid' ClientSecret = 'mysecret' Left = 304 Top = 440 end *) procedure TUniMainModule.UploadtoCloud(file_path: String); var LURL, cloud_path, local_filename, local_file_path: String; upload_stream: TFileStream; begin //path : the path to the file you want to update local_filename:= 'test.txt'; cloud_path:= 'Test\'; //file : Absolute path to the local file you want to upload local_file_path:= 'D:\TK\uniGUI\WebApp\Win64\Debug\test.txt'; //change Request Settings RESTRequest1.Method:= TRestRequestMethod.rmPUT; // REST.Types RESTClient1.BaseURL:= 'https://api-content.dropbox.com/1/'; //Using auto, automatically selects dropbox or sandbox folders LURL:= 'files_put/auto/'+ EncodeURIComponent(cloud_path); RESTRequest1.Resource:= LURL; //Open File to FileStream upload_stream:= TFileStream.Create(local_file_path, fmOpenRead); upload_stream.Position:= 0; //Set Content-Type to text/plain RESTRequest1.Params.AddHeader('Content-Type', 'text/plain'); //Set Request Body to FileStream RESTRequest1.ClearBody; RESTRequest1.AddBody(upload_stream, TRESTContentType.ctTEXT_PLAIN); try RESTRequest1.Execute; except on e: Exception do begin ShowMessage(e.Message); end; end; upload_stream.Free; end; Quote Link to comment Share on other sites More sharing options...
andyhill Posted November 26, 2018 Author Share Posted November 26, 2018 Help would be appreciated Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.