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
(DataFlex) Frame.io - Upload an AssetUpload an asset to Frame.io For more information, see https://docs.frame.io/docs/uploading-assets
Use ChilkatAx-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.