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

SQL Server Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(SQL Server) Create a Temporary Public Link to a DropBox File

Get a temporary link to stream content of a file. This link will expire in four hours and afterwards you will get 410 Gone.

For more information, see https://www.dropbox.com/developers/documentation/http/documentation#files-get_temporary_link

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

-- 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 -X POST https://api.dropboxapi.com/2/files/get_temporary_link \
    --     --header "Authorization: Bearer DROPBOX_ACCESS_TOKEN" \
    --     --header "Content-Type: application/json" \
    --     --data "{\"path\": \"/video.mp4\"}"

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

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

    -- {
    --   "path": "/video.mp4"
    -- }

    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, 'UpdateString', @success OUT, 'path', '/video.mp4'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', 'Bearer DROPBOX_ACCESS_TOKEN'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.dropboxapi.com/2/files/get_temporary_link', '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 @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 @json
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @resp

    -- Sample JSON response:
    -- (Sample code for parsing the JSON response is shown below)

    -- {
    --   "metadata": {
    --     "name": "Prime_Numbers.txt",
    --     "id": "id:a4ayc_80_OEAAAAAAAAAXw",
    --     "client_modified": "2015-05-12T15:50:38Z",
    --     "server_modified": "2015-05-12T15:50:38Z",
    --     "rev": "a1c10ce0dd78",
    --     "size": 7212,
    --     "path_lower": "/homework/math/prime_numbers.txt",
    --     "path_display": "/Homework/math/Prime_Numbers.txt",
    --     "sharing_info": {
    --       "read_only": true,
    --       "parent_shared_folder_id": "84528192421",
    --       "modified_by": "dbid:AAH4f99T0taONIb-OurWxbNQ6ywGRopQngc"
    --     },
    --     "is_downloadable": true,
    --     "property_groups": [
    --       {
    --         "template_id": "ptid:1a5n2i6d3OYEAAAAAAAAAYa",
    --         "fields": [
    --           {
    --             "name": "Security Policy",
    --             "value": "Confidential"
    --           }
    --         ]
    --       }
    --     ],
    --     "has_explicit_shared_members": false,
    --     "content_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
    --   },
    --   "link": "https://dl.dropboxusercontent.com/apitl/1/YXNkZmFzZGcyMzQyMzI0NjU2NDU2NDU2"
    -- }

    -- Sample code for parsing the JSON response...
    -- Use the following online tool to generate parsing code from sample JSON:
    -- Generate Parsing Code from JSON

    DECLARE @template_id nvarchar(4000)

    DECLARE @j int

    DECLARE @count_j int

    DECLARE @name nvarchar(4000)

    DECLARE @value nvarchar(4000)

    DECLARE @metadataName nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @metadataName OUT, 'metadata.name'
    DECLARE @metadataId nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @metadataId OUT, 'metadata.id'
    DECLARE @metadataClient_modified nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @metadataClient_modified OUT, 'metadata.client_modified'
    DECLARE @metadataServer_modified nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @metadataServer_modified OUT, 'metadata.server_modified'
    DECLARE @metadataRev nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @metadataRev OUT, 'metadata.rev'
    DECLARE @metadataSize int
    EXEC sp_OAMethod @jResp, 'IntOf', @metadataSize OUT, 'metadata.size'
    DECLARE @metadataPath_lower nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @metadataPath_lower OUT, 'metadata.path_lower'
    DECLARE @metadataPath_display nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @metadataPath_display OUT, 'metadata.path_display'
    DECLARE @metadataSharing_infoRead_only int
    EXEC sp_OAMethod @jResp, 'BoolOf', @metadataSharing_infoRead_only OUT, 'metadata.sharing_info.read_only'
    DECLARE @metadataSharing_infoParent_shared_folder_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @metadataSharing_infoParent_shared_folder_id OUT, 'metadata.sharing_info.parent_shared_folder_id'
    DECLARE @metadataSharing_infoModified_by nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @metadataSharing_infoModified_by OUT, 'metadata.sharing_info.modified_by'
    DECLARE @metadataIs_downloadable int
    EXEC sp_OAMethod @jResp, 'BoolOf', @metadataIs_downloadable OUT, 'metadata.is_downloadable'
    DECLARE @metadataHas_explicit_shared_members int
    EXEC sp_OAMethod @jResp, 'BoolOf', @metadataHas_explicit_shared_members OUT, 'metadata.has_explicit_shared_members'
    DECLARE @metadataContent_hash nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @metadataContent_hash OUT, 'metadata.content_hash'
    DECLARE @link nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @link OUT, 'link'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'metadata.property_groups'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @template_id OUT, 'metadata.property_groups[i].template_id'
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'metadata.property_groups[i].fields'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'metadata.property_groups[i].fields[j].name'
            EXEC sp_OAMethod @jResp, 'StringOf', @value OUT, 'metadata.property_groups[i].fields[j].value'
            SELECT @j = @j + 1
          END
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

 

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