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
(SQL Server) Frame.io - Upload an AssetUpload an asset to Frame.io For more information, see https://docs.frame.io/docs/uploading-assets
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) -- This example assumes the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. DECLARE @http int -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int -- 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" -- } DECLARE @localFilePath nvarchar(4000) SELECT @localFilePath = 'qa_data/mp4/rotating_earth.mp4' DECLARE @fac int -- Use "Chilkat_9_5_0.FileAccess" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.FileAccess', @fac OUT DECLARE @fileSize int EXEC sp_OAMethod @fac, 'FileSize', @fileSize OUT, @localFilePath DECLARE @json int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filesize', @fileSize EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filetype', 'video/mp4' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'name', 'rotating_earth7' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'type', 'file' EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'content-type', 'application/json' -- Adds the "Authorization: Bearer <FRAME_IO_DEV_TOKEN>" header. EXEC sp_OASetProperty @http, 'AuthToken', '<FRAME_IO_DEV_TOKEN>' -- Uploading to asset ID: 039845e8-bffe-4d6b-88d3-c780bae06342 DECLARE @resp int EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.frame.io/v2/assets/039845e8-bffe-4d6b-88d3-c780bae06342/children', 'application/json', @json EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 = 0 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @fac EXEC @hr = sp_OADestroy @json RETURN END DECLARE @sbResponseBody int -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody DECLARE @jResp int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody EXEC sp_OASetProperty @jResp, 'EmitCompact', 0 PRINT 'Response Body:' EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT PRINT @sTmp0 DECLARE @respStatusCode int EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT PRINT 'Response Status Code = ' + @respStatusCode IF @respStatusCode >= 400 BEGIN PRINT 'Response Header:' EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT PRINT @sTmp0 PRINT 'Failed.' EXEC @hr = sp_OADestroy @resp EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @fac EXEC @hr = sp_OADestroy @json EXEC @hr = sp_OADestroy @sbResponseBody EXEC @hr = sp_OADestroy @jResp RETURN END EXEC @hr = sp_OADestroy @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. DECLARE @numChunks int EXEC sp_OAMethod @jResp, 'SizeOfArray', @numChunks OUT, 'upload_urls' DECLARE @sizePerChunk int SELECT @sizePerChunk = (@fileSize + @numChunks - 1) / @numChunks PRINT 'numChunks = ' + @numChunks PRINT 'sizePerChunk = ' + @sizePerChunk EXEC sp_OAMethod @fac, 'OpenForRead', @success OUT, @localFilePath IF @success = 0 BEGIN EXEC sp_OAGetProperty @fac, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @fac EXEC @hr = sp_OADestroy @json EXEC @hr = sp_OADestroy @sbResponseBody EXEC @hr = sp_OADestroy @jResp RETURN END DECLARE @bd int -- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT DECLARE @httpForUpload int -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Http', @httpForUpload OUT EXEC sp_OAMethod @httpForUpload, 'SetRequestHeader', NULL, 'x-amz-acl', 'private' DECLARE @i int SELECT @i = 0 WHILE (@i < @numChunks) BEGIN EXEC sp_OAMethod @bd, 'Clear', @success OUT EXEC sp_OAMethod @fac, 'ReadBlockBd', @success OUT, @i, @sizePerChunk, @bd EXEC sp_OASetProperty @jResp, 'I', @i DECLARE @uploadUrl nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @uploadUrl OUT, 'upload_urls[i]' -- Send the chunk in a PUT: PRINT 'PUT chunk ' + @i + 1 PRINT 'URL: ' + @uploadUrl -- PUT https://frameio-uploads-production.s3/etc/etc -- Content-Type: video/mp4 -- x-amz-acl: private EXEC sp_OAMethod @httpForUpload, 'PBinaryBd', @resp OUT, 'PUT', @uploadUrl, @bd, 'video/mp4', 0, 0 EXEC sp_OAGetProperty @httpForUpload, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 = 0 BEGIN EXEC sp_OAGetProperty @httpForUpload, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @fac EXEC @hr = sp_OADestroy @json EXEC @hr = sp_OADestroy @sbResponseBody EXEC @hr = sp_OADestroy @jResp EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @httpForUpload RETURN END EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT PRINT 'response status: ' + @iTmp0 EXEC @hr = sp_OADestroy @resp SELECT @i = @i + 1 END EXEC sp_OAMethod @fac, 'FileClose', NULL PRINT 'File uploaded.' EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @fac EXEC @hr = sp_OADestroy @json EXEC @hr = sp_OADestroy @sbResponseBody EXEC @hr = sp_OADestroy @jResp EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @httpForUpload END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.