Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PureBasic Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
JCC Cyprus
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(PureBasic) 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.

For more information, see https://support.bunny.net/hc/en-us/articles/360016055099-How-to-sign-URLs-for-BunnyCDN-Token-Authentication

Chilkat PureBasic Module Download

Chilkat PureBasic Module

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.