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
(PureBasic) 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
IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkUrl.pb" IncludeFile "CkDateTime.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. success.i mySecurityKey.s = "e7ea8d73-8fa0-44ef-a2cc-91526f7df5ed" url.s = "https://test.b-cdn.net/sample-pdf-with-images.pdf" ; Extract the URL components. urlObj.i = CkUrl::ckCreate() If urlObj.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkUrl::ckParseUrl(urlObj,url) url_scheme.s = "https" If CkUrl::ckSsl(urlObj) = 0 url_scheme = "http" EndIf url_host.s = CkUrl::ckHost(urlObj) url_path.s = CkUrl::ckPath(urlObj) ; Calculate an expiration time 1 hour from the current date/time. expTime.i = CkDateTime::ckCreate() If expTime.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkDateTime::ckSetFromCurrentSystemTime(expTime) CkDateTime::ckAddSeconds(expTime,3600) expires.s = CkDateTime::ckGetAsUnixTimeStr(expTime,0) Debug "Expires = " + expires ; Create the string to hash sbToHash.i = CkStringBuilder::ckCreate() If sbToHash.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sbToHash,mySecurityKey) CkStringBuilder::ckAppend(sbToHash,url_path) CkStringBuilder::ckAppend(sbToHash,expires) ; Base64Url encoding is the same as base64, except "-" is used instead of "+", ; "_" is used instead of "/", and no "=" padding is added. token.s = CkStringBuilder::ckGetHash(sbToHash,"sha256","base64Url","utf-8") sbSignedUrl.i = CkStringBuilder::ckCreate() If sbSignedUrl.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sbSignedUrl,url_scheme) CkStringBuilder::ckAppend(sbSignedUrl,"://") CkStringBuilder::ckAppend(sbSignedUrl,url_host) CkStringBuilder::ckAppend(sbSignedUrl,url_path) CkStringBuilder::ckAppend(sbSignedUrl,"?token=") CkStringBuilder::ckAppend(sbSignedUrl,token) CkStringBuilder::ckAppend(sbSignedUrl,"&expires=") CkStringBuilder::ckAppend(sbSignedUrl,expires) signedUrl.s = CkStringBuilder::ckGetAsString(sbSignedUrl) Debug "Signed URL: " + signedUrl ; Use the signed URL to download the file. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkHttp::ckDownload(http,signedUrl,"c:/aaworkarea/sample.pdf") If success = 0 Debug CkHttp::ckLastErrorText(http) Else Debug "Success." EndIf CkUrl::ckDispose(urlObj) CkDateTime::ckDispose(expTime) CkStringBuilder::ckDispose(sbToHash) CkStringBuilder::ckDispose(sbSignedUrl) CkHttp::ckDispose(http) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.