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

DataFlex 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
Jira
Lightspeed
MYOB
Magento
Mailgun

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
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
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

 

 

 

(DataFlex) Frame.io - Upload an Asset

Upload an asset to Frame.io

For more information, see https://docs.frame.io/docs/uploading-assets

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    String sLocalFilePath
    Handle hoFac
    Integer iFileSize
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    Integer iNumChunks
    Integer iSizePerChunk
    Variant vBd
    Handle hoBd
    Handle hoHttpForUpload
    Integer i
    String sUploadUrl
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // Implements the following CURL command:

    // curl --request POST \
    //   --url https://api.frame.io/v2/assets/<ASSET_ID>/children \
    //   --header 'authorization: Bearer <FRAME_IO_DEV_TOKEN>' \
    //   --header 'content-type: application/json' \
    //   --data '{"filesize":1570024 ,"filetype":"video/mp4","name":"rotating_earth","type":"file"}'

    // Use the following online tool to generate HTTP code from a CURL command
    // Convert a cURL Command to HTTP Source Code

    // Use this online tool to generate code from sample JSON:
    // Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "filesize": 1570024,
    //   "filetype": "video/mp4",
    //   "name": "rotating_earth",
    //   "type": "file"
    // }

    Move "qa_data/mp4/rotating_earth.mp4" To sLocalFilePath
    Get Create (RefClass(cComCkFileAccess)) To hoFac
    If (Not(IsComObjectCreated(hoFac))) Begin
        Send CreateComObject of hoFac
    End
    Get ComFileSize Of hoFac sLocalFilePath To iFileSize

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateInt Of hoJson "filesize" iFileSize To iSuccess
    Get ComUpdateString Of hoJson "filetype" "video/mp4" To iSuccess
    Get ComUpdateString Of hoJson "name" "rotating_earth7" To iSuccess
    Get ComUpdateString Of hoJson "type" "file" To iSuccess

    Send ComSetRequestHeader To hoHttp "content-type" "application/json"
    // Adds the "Authorization: Bearer <FRAME_IO_DEV_TOKEN>" header.
    Set ComAuthToken Of hoHttp To "<FRAME_IO_DEV_TOKEN>"

    // Uploading to asset ID: 039845e8-bffe-4d6b-88d3-c780bae06342
    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp "https://api.frame.io/v2/assets/039845e8-bffe-4d6b-88d3-c780bae06342/children" "application/json" vJson To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

    // Upload in chunks to the pre-signed S3 upload URLs.
    // There are ways to do this in parallel, but for simplicity we'll show how to upload
    // one chunk after another.
    Get ComSizeOfArray Of hoJResp "upload_urls" To iNumChunks
    Move ((iFileSize + iNumChunks - 1) / iNumChunks) To iSizePerChunk

    Showln "numChunks = " iNumChunks
    Showln "sizePerChunk = " iSizePerChunk

    Get ComOpenForRead Of hoFac sLocalFilePath To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFac To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatBinData)) To hoBd
    If (Not(IsComObjectCreated(hoBd))) Begin
        Send CreateComObject of hoBd
    End
    Get Create (RefClass(cComChilkatHttp)) To hoHttpForUpload
    If (Not(IsComObjectCreated(hoHttpForUpload))) Begin
        Send CreateComObject of hoHttpForUpload
    End

    Send ComSetRequestHeader To hoHttpForUpload "x-amz-acl" "private"

    Move 0 To i
    While (i < iNumChunks)
        Get ComClear Of hoBd To iSuccess
        Get pvComObject of hoBd to vBd
        Get ComReadBlockBd Of hoFac i iSizePerChunk vBd To iSuccess

        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "upload_urls[i]" To sUploadUrl

        // Send the chunk in a PUT:

        Showln "PUT chunk " (i + 1)
        Showln "URL: " sUploadUrl

        // PUT https://frameio-uploads-production.s3/etc/etc
        // Content-Type: video/mp4
        // x-amz-acl: private

        Get pvComObject of hoBd to vBd
        Get ComPBinaryBd Of hoHttpForUpload "PUT" sUploadUrl vBd "video/mp4" False False To vResp
        If (IsComObject(vResp)) Begin
            Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
            Set pvComObject Of hoResp To vResp
        End
        Get ComLastMethodSuccess Of hoHttpForUpload To bTemp1
        If (bTemp1 = False) Begin
            Get ComLastErrorText Of hoHttpForUpload To sTemp1
            Showln sTemp1
            Procedure_Return
        End

        Get ComStatusCode Of hoResp To iTemp1
        Showln "response status: " iTemp1

        Send Destroy of hoResp

        Move (i + 1) To i
    Loop

    Send ComFileClose To hoFac

    Showln "File uploaded."


End_Procedure

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.