Visual FoxPro
Visual FoxPro
Bunny Sign URL and then Download using Signed URL
See more Bunny CDN Examples
Shows how to sign a URL for BunnyCDN Token Authentication and then use it to download.Chilkat Visual FoxPro Downloads
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
lnSuccess = 0
* 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.
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.
loExpTime = CreateObject('Chilkat.CkDateTime')
loExpTime.SetFromCurrentSystemTime()
loExpTime.AddSeconds(3600)
lcExpires = loExpTime.GetAsUnixTimeStr(0)
? "Expires = " + lcExpires
* Create the string to hash
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")
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.
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