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
(Visual FoxPro) 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
LOCAL lnSuccess LOCAL lcMySecurityKey LOCAL lcUrl LOCAL loUrlObj LOCAL lcUrl_scheme LOCAL lcUrl_host LOCAL lcUrl_path LOCAL loExpTime LOCAL lcExpires LOCAL loSbToHash LOCAL lcToken LOCAL loSbSignedUrl LOCAL lcSignedUrl LOCAL loHttp * This example assumes the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. lcMySecurityKey = "e7ea8d73-8fa0-44ef-a2cc-91526f7df5ed" lcUrl = "https://test.b-cdn.net/sample-pdf-with-images.pdf" * Extract the URL components. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Url') loUrlObj = CreateObject('Chilkat.Url') loUrlObj.ParseUrl(lcUrl) lcUrl_scheme = "https" IF (loUrlObj.Ssl = 0) THEN lcUrl_scheme = "http" ENDIF lcUrl_host = loUrlObj.Host lcUrl_path = loUrlObj.Path * Calculate an expiration time 1 hour from the current date/time. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.CkDateTime') loExpTime = CreateObject('Chilkat.CkDateTime') loExpTime.SetFromCurrentSystemTime() loExpTime.AddSeconds(3600) lcExpires = loExpTime.GetAsUnixTimeStr(0) ? "Expires = " + lcExpires * Create the string to hash * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbToHash = CreateObject('Chilkat.StringBuilder') loSbToHash.Append(lcMySecurityKey) loSbToHash.Append(lcUrl_path) loSbToHash.Append(lcExpires) * Base64Url encoding is the same as base64, except "-" is used instead of "+", * "_" is used instead of "/", and no "=" padding is added. lcToken = loSbToHash.GetHash("sha256","base64Url","utf-8") * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbSignedUrl = CreateObject('Chilkat.StringBuilder') loSbSignedUrl.Append(lcUrl_scheme) loSbSignedUrl.Append("://") loSbSignedUrl.Append(lcUrl_host) loSbSignedUrl.Append(lcUrl_path) loSbSignedUrl.Append("?token=") loSbSignedUrl.Append(lcToken) loSbSignedUrl.Append("&expires=") loSbSignedUrl.Append(lcExpires) lcSignedUrl = loSbSignedUrl.GetAsString() ? "Signed URL: " + lcSignedUrl * Use the signed URL to download the file. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http') loHttp = CreateObject('Chilkat.Http') lnSuccess = loHttp.Download(lcSignedUrl,"c:/aaworkarea/sample.pdf") IF (lnSuccess = 0) THEN ? loHttp.LastErrorText ELSE ? "Success." ENDIF RELEASE loUrlObj RELEASE loExpTime RELEASE loSbToHash RELEASE loSbSignedUrl RELEASE loHttp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.