Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) Upload String to DropboxUploads a string to a file on Dropbox. This example can upload content up to 150MB, assuming a 150MB string fits in memory for your app. Larger files must be uploaded with an upload session (upload_session/start).
integer li_rc oleobject loo_Rest integer li_Success string ls_Content oleobject loo_Json string ls_ResponseStr oleobject loo_JsonResp integer li_Size string ls_Rev string ls_ClientModified oleobject loo_Ckdt integer li_BLocalTime oleobject loo_Dt // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // A Dropbox access token should have been previously obtained. // Dropbox access tokens do not expire. // See Dropbox Access Token. loo_Rest = create oleobject // Use "Chilkat_9_5_0.Rest" for versions of Chilkat < 10.0.0 li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest") if li_rc < 0 then destroy loo_Rest MessageBox("Error","Connecting to COM object failed") return end if // Connect to Dropbox li_Success = loo_Rest.Connect("content.dropboxapi.com",443,1,1) if li_Success <> 1 then Write-Debug loo_Rest.LastErrorText destroy loo_Rest return end if // Add request headers. loo_Rest.AddHeader("Content-Type","application/octet-stream") loo_Rest.AddHeader("Authorization","Bearer DROPBOX_ACCESS_TOKEN") // The upload "parameters" contained in JSON passed in an HTTP request header. // This is the JSON to be added in this example: // { // "path": "/jack.txt", // "mode": "add", // "autorename": true, // "mute": false // } // This will be the content of the file created in Dropbox. ls_Content = "All work and no play makes Jack a dull boy" loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") loo_Json.AppendString("path","/jack.txt") loo_Json.AppendString("mode","add") loo_Json.AppendBool("autorename",1) loo_Json.AppendBool("mute",0) loo_Rest.AddHeader("Dropbox-API-Arg",loo_Json.Emit()) // Do the upload. The URL is https://content.dropboxapi.com/2/files/upload. // We already connected to content.dropboxapi.com using TLS (i.e. HTTPS), // so now we only need to specify the path "/2/files/upload". ls_ResponseStr = loo_Rest.FullRequestString("POST","/2/files/upload",ls_Content) if loo_Rest.LastMethodSuccess <> 1 then Write-Debug loo_Rest.LastErrorText destroy loo_Rest destroy loo_Json return end if // When successful, Dropbox responds with a 200 response code. if loo_Rest.ResponseStatusCode <> 200 then // Examine the request/response to see what happened. Write-Debug "response status code = " + string(loo_Rest.ResponseStatusCode) Write-Debug "response status text = " + loo_Rest.ResponseStatusText Write-Debug "response header: " + loo_Rest.ResponseHeader Write-Debug "response body (if any): " + ls_ResponseStr Write-Debug "---" Write-Debug "LastRequestStartLine: " + loo_Rest.LastRequestStartLine Write-Debug "LastRequestHeader: " + loo_Rest.LastRequestHeader destroy loo_Rest destroy loo_Json return end if Write-Debug "LastRequestHeader: " + loo_Rest.LastRequestHeader // The response is JSON. loo_JsonResp = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JsonResp.ConnectToNewObject("Chilkat.JsonObject") loo_JsonResp.EmitCompact = 0 loo_JsonResp.Load(ls_ResponseStr) // Show the JSON response. Write-Debug loo_JsonResp.Emit() // Returns JSON that looks like this: // { // "name": "jack.txt", // "path_lower": "/jack.txt", // "path_display": "/jack.txt", // "id": "id:yqx4-tE_NKAAAAAAAAAAAQ", // "client_modified": "2016-06-02T20:42:11Z", // "server_modified": "2016-06-02T20:42:11Z", // "rev": "8482db15f", // "size": 42 // } // Sample code to get data from the JSON response: li_Size = loo_JsonResp.IntOf("size") Write-Debug "size = " + string(li_Size) ls_Rev = loo_JsonResp.StringOf("rev") Write-Debug "rev = " + ls_Rev ls_ClientModified = loo_JsonResp.StringOf("client_modified") loo_Ckdt = create oleobject // Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0 li_rc = loo_Ckdt.ConnectToNewObject("Chilkat.CkDateTime") loo_Ckdt.SetFromTimestamp(ls_ClientModified) li_BLocalTime = 1 loo_Dt = loo_Ckdt.GetDtObj(li_BLocalTime) Write-Debug string(loo_Dt.Day) + "/" + string(loo_Dt.Month) + "/" + string(loo_Dt.Year) + " " + string(loo_Dt.Hour) + ":" + string(loo_Dt.Minute) destroy loo_Dt destroy loo_Rest destroy loo_Json destroy loo_JsonResp destroy loo_Ckdt |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.