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
(PowerBuilder) Frame.io - Upload an AssetUpload an asset to Frame.io For more information, see https://docs.frame.io/docs/uploading-assets
integer li_rc oleobject loo_Http integer li_Success string ls_LocalFilePath oleobject loo_Fac integer li_FileSize oleobject loo_Json oleobject loo_Resp oleobject loo_SbResponseBody oleobject loo_JResp integer li_RespStatusCode integer li_NumChunks integer li_SizePerChunk oleobject loo_Bd oleobject loo_HttpForUpload integer i string ls_UploadUrl // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") if li_rc < 0 then destroy loo_Http MessageBox("Error","Connecting to COM object failed") return end if // 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" // } ls_LocalFilePath = "qa_data/mp4/rotating_earth.mp4" loo_Fac = create oleobject // Use "Chilkat_9_5_0.FileAccess" for versions of Chilkat < 10.0.0 li_rc = loo_Fac.ConnectToNewObject("Chilkat.FileAccess") li_FileSize = loo_Fac.FileSize(ls_LocalFilePath) loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") loo_Json.UpdateInt("filesize",li_FileSize) loo_Json.UpdateString("filetype","video/mp4") loo_Json.UpdateString("name","rotating_earth7") loo_Json.UpdateString("type","file") loo_Http.SetRequestHeader("content-type","application/json") // Adds the "Authorization: Bearer <FRAME_IO_DEV_TOKEN>" header. loo_Http.AuthToken = "<FRAME_IO_DEV_TOKEN>" // Uploading to asset ID: 039845e8-bffe-4d6b-88d3-c780bae06342 loo_Resp = loo_Http.PostJson3("https://api.frame.io/v2/assets/039845e8-bffe-4d6b-88d3-c780bae06342/children","application/json",loo_Json) if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Http destroy loo_Fac destroy loo_Json return end if loo_SbResponseBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder") loo_Resp.GetBodySb(loo_SbResponseBody) loo_JResp = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject") loo_JResp.LoadSb(loo_SbResponseBody) loo_JResp.EmitCompact = 0 Write-Debug "Response Body:" Write-Debug loo_JResp.Emit() li_RespStatusCode = loo_Resp.StatusCode Write-Debug "Response Status Code = " + string(li_RespStatusCode) if li_RespStatusCode >= 400 then Write-Debug "Response Header:" Write-Debug loo_Resp.Header Write-Debug "Failed." destroy loo_Resp destroy loo_Http destroy loo_Fac destroy loo_Json destroy loo_SbResponseBody destroy loo_JResp return end if destroy loo_Resp // 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. li_NumChunks = loo_JResp.SizeOfArray("upload_urls") li_SizePerChunk = (li_FileSize + li_NumChunks - 1) / li_NumChunks Write-Debug "numChunks = " + string(li_NumChunks) Write-Debug "sizePerChunk = " + string(li_SizePerChunk) li_Success = loo_Fac.OpenForRead(ls_LocalFilePath) if li_Success = 0 then Write-Debug loo_Fac.LastErrorText destroy loo_Http destroy loo_Fac destroy loo_Json destroy loo_SbResponseBody destroy loo_JResp return end if loo_Bd = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData") loo_HttpForUpload = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_HttpForUpload.ConnectToNewObject("Chilkat.Http") loo_HttpForUpload.SetRequestHeader("x-amz-acl","private") i = 0 do while (i < li_NumChunks) loo_Bd.Clear() li_Success = loo_Fac.ReadBlockBd(i,li_SizePerChunk,loo_Bd) loo_JResp.I = i ls_UploadUrl = loo_JResp.StringOf("upload_urls[i]") // Send the chunk in a PUT: Write-Debug "PUT chunk " + string(i + 1) Write-Debug "URL: " + ls_UploadUrl // PUT https://frameio-uploads-production.s3/etc/etc // Content-Type: video/mp4 // x-amz-acl: private loo_Resp = loo_HttpForUpload.PBinaryBd("PUT",ls_UploadUrl,loo_Bd,"video/mp4",0,0) if loo_HttpForUpload.LastMethodSuccess = 0 then Write-Debug loo_HttpForUpload.LastErrorText destroy loo_Http destroy loo_Fac destroy loo_Json destroy loo_SbResponseBody destroy loo_JResp destroy loo_Bd destroy loo_HttpForUpload return end if Write-Debug "response status: " + string(loo_Resp.StatusCode) destroy loo_Resp i = i + 1 loop loo_Fac.FileClose() Write-Debug "File uploaded." destroy loo_Http destroy loo_Fac destroy loo_Json destroy loo_SbResponseBody destroy loo_JResp destroy loo_Bd destroy loo_HttpForUpload |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.