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) Bunny Sign URL and then Download using Signed URLSee more Bunny CDN ExamplesShows how to sign a URL for BunnyCDN Token Authentication and then use it to download. For more information, see https://support.bunny.net/hc/en-us/articles/360016055099-How-to-sign-URLs-for-BunnyCDN-Token-Authentication
integer li_rc integer li_Success string ls_MySecurityKey string ls_Url oleobject loo_UrlObj string ls_Url_scheme string ls_Url_host string ls_Url_path oleobject loo_ExpTime string ls_Expires oleobject loo_SbToHash string ls_Token oleobject loo_SbSignedUrl string ls_SignedUrl oleobject loo_Http // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. ls_MySecurityKey = "e7ea8d73-8fa0-44ef-a2cc-91526f7df5ed" ls_Url = "https://test.b-cdn.net/sample-pdf-with-images.pdf" // Extract the URL components. loo_UrlObj = create oleobject // Use "Chilkat_9_5_0.Url" for versions of Chilkat < 10.0.0 li_rc = loo_UrlObj.ConnectToNewObject("Chilkat.Url") if li_rc < 0 then destroy loo_UrlObj MessageBox("Error","Connecting to COM object failed") return end if loo_UrlObj.ParseUrl(ls_Url) ls_Url_scheme = "https" if loo_UrlObj.Ssl = 0 then ls_Url_scheme = "http" end if ls_Url_host = loo_UrlObj.Host ls_Url_path = loo_UrlObj.Path // Calculate an expiration time 1 hour from the current date/time. loo_ExpTime = create oleobject // Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0 li_rc = loo_ExpTime.ConnectToNewObject("Chilkat.CkDateTime") loo_ExpTime.SetFromCurrentSystemTime() loo_ExpTime.AddSeconds(3600) ls_Expires = loo_ExpTime.GetAsUnixTimeStr(0) Write-Debug "Expires = " + ls_Expires // Create the string to hash loo_SbToHash = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbToHash.ConnectToNewObject("Chilkat.StringBuilder") loo_SbToHash.Append(ls_MySecurityKey) loo_SbToHash.Append(ls_Url_path) loo_SbToHash.Append(ls_Expires) // Base64Url encoding is the same as base64, except "-" is used instead of "+", // "_" is used instead of "/", and no "=" padding is added. ls_Token = loo_SbToHash.GetHash("sha256","base64Url","utf-8") loo_SbSignedUrl = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbSignedUrl.ConnectToNewObject("Chilkat.StringBuilder") loo_SbSignedUrl.Append(ls_Url_scheme) loo_SbSignedUrl.Append("://") loo_SbSignedUrl.Append(ls_Url_host) loo_SbSignedUrl.Append(ls_Url_path) loo_SbSignedUrl.Append("?token=") loo_SbSignedUrl.Append(ls_Token) loo_SbSignedUrl.Append("&expires=") loo_SbSignedUrl.Append(ls_Expires) ls_SignedUrl = loo_SbSignedUrl.GetAsString() Write-Debug "Signed URL: " + ls_SignedUrl // Use the signed URL to download the file. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") li_Success = loo_Http.Download(ls_SignedUrl,"c:/aaworkarea/sample.pdf") if li_Success = 0 then Write-Debug loo_Http.LastErrorText else Write-Debug "Success." end if destroy loo_UrlObj destroy loo_ExpTime destroy loo_SbToHash destroy loo_SbSignedUrl destroy loo_Http |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.