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
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) Dropbox File Streaming Upload

Upload a file to Drobox using a file stream. This example can upload files up to 150MB. Larger files must be uploaded with an upload session (upload_session/start).

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
    DECLARE @iTmp1 int
    DECLARE @iTmp2 int
    DECLARE @iTmp3 int
    DECLARE @iTmp4 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example requires the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    -- A Dropbox access token should have been previously obtained.
    -- Dropbox access tokens do not expire.
    -- See Dropbox Access Token.

    DECLARE @rest int
    -- Use "Chilkat_9_5_0.Rest" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Rest', @rest OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- Connect to Dropbox
    DECLARE @success int
    EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'content.dropboxapi.com', 443, 1, 1
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        RETURN
      END

    -- Add request headers.
    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Type', 'application/octet-stream'
    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Authorization', 'Bearer DROPBOX_ACCESS_TOKEN'

    -- The upload "parameters" contained in JSON passed in an HTTP request header.
    -- This is the JSON to be added in this example:
    -- { 
    --    "path": "/Homework/lit/hamlet.xml",
    --    "mode": "add",
    --    "autorename": true,
    --    "mute": false
    -- }

    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, 'AppendString', @success OUT, 'path', '/Homework/lit/hamlet.xml'
    EXEC sp_OAMethod @json, 'AppendString', @success OUT, 'mode', 'add'
    EXEC sp_OAMethod @json, 'AppendBool', @success OUT, 'autorename', 1
    EXEC sp_OAMethod @json, 'AppendBool', @success OUT, 'mute', 0
    EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT
    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Dropbox-API-Arg', @sTmp0

    -- Almost ready to go...
    -- Let's setup a file stream to point to a file.
    DECLARE @fileStream int
    -- Use "Chilkat_9_5_0.Stream" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Stream', @fileStream OUT

    EXEC sp_OASetProperty @fileStream, 'SourceFile', 'qa_data/xml/hamlet.xml'

    -- Do the upload.  The URL is https://content.dropboxapi.com/2/files/upload.
    -- We already connected to content.dropboxapi.com using TLS (i.e. HTTPS),
    -- so now we only need to specify the path "/2/files/upload".

    -- Note: The file is streamed directly from disk.  (The entire
    -- file will not be loaded into memory.)
    DECLARE @responseStr nvarchar(4000)
    EXEC sp_OAMethod @rest, 'FullRequestStream', @responseStr OUT, 'POST', '/2/files/upload', @fileStream
    EXEC sp_OAGetProperty @rest, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @fileStream
        RETURN
      END

    -- When successful, Dropbox responds with a 200 response code.
    EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
    IF @iTmp0 <> 200
      BEGIN
        -- Examine the request/response to see what happened.

        EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
        PRINT 'response status code = ' + @iTmp0

        EXEC sp_OAGetProperty @rest, 'ResponseStatusText', @sTmp0 OUT
        PRINT 'response status text = ' + @sTmp0

        EXEC sp_OAGetProperty @rest, 'ResponseHeader', @sTmp0 OUT
        PRINT 'response header: ' + @sTmp0

        PRINT 'response body (if any): ' + @responseStr

        PRINT '---'

        EXEC sp_OAGetProperty @rest, 'LastRequestStartLine', @sTmp0 OUT
        PRINT 'LastRequestStartLine: ' + @sTmp0

        EXEC sp_OAGetProperty @rest, 'LastRequestHeader', @sTmp0 OUT
        PRINT 'LastRequestHeader: ' + @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @fileStream
        RETURN
      END

    -- The response is JSON.
    DECLARE @jsonResp int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonResp OUT

    EXEC sp_OASetProperty @jsonResp, 'EmitCompact', 0
    EXEC sp_OAMethod @jsonResp, 'Load', @success OUT, @responseStr

    -- Show the JSON response.
    EXEC sp_OAMethod @jsonResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    -- Returns JSON that looks like this:
    -- { 
    --   "name": "hamlet.xml",
    --   "path_lower": "/homework/lit/hamlet.xml",
    --   "path_display": "/Homework/lit/hamlet.xml",
    --   "id": "id:74FkdeNuyKAAAAAAAAAAAQ",
    --   "client_modified": "2016-06-02T23:19:00Z",
    --   "server_modified": "2016-06-02T23:19:00Z",
    --   "rev": "9482db15f",
    --   "size": 279658
    -- }

    -- Sample code to get data from the JSON response:
    DECLARE @size int
    EXEC sp_OAMethod @jsonResp, 'IntOf', @size OUT, 'size'

    PRINT 'size = ' + @size

    DECLARE @rev nvarchar(4000)
    EXEC sp_OAMethod @jsonResp, 'StringOf', @rev OUT, 'rev'

    PRINT 'rev = ' + @rev

    DECLARE @clientModified nvarchar(4000)
    EXEC sp_OAMethod @jsonResp, 'StringOf', @clientModified OUT, 'client_modified'
    DECLARE @ckdt int
    -- Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.CkDateTime', @ckdt OUT

    EXEC sp_OAMethod @ckdt, 'SetFromTimestamp', @success OUT, @clientModified
    DECLARE @bLocalTime int
    SELECT @bLocalTime = 1
    DECLARE @dt int
    EXEC sp_OAMethod @ckdt, 'GetDtObj', @dt OUT, @bLocalTime
    EXEC sp_OAGetProperty @dt, 'Day', @iTmp0 OUT

    EXEC sp_OAGetProperty @dt, 'Month', @iTmp1 OUT

    EXEC sp_OAGetProperty @dt, 'Year', @iTmp2 OUT

    EXEC sp_OAGetProperty @dt, 'Hour', @iTmp3 OUT

    EXEC sp_OAGetProperty @dt, 'Minute', @iTmp4 OUT
    PRINT @iTmp0 + '/' + @iTmp1 + '/' + @iTmp2 + ' ' + @iTmp3 + ':' + @iTmp4
    EXEC @hr = sp_OADestroy @dt


    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @fileStream
    EXEC @hr = sp_OADestroy @jsonResp
    EXEC @hr = sp_OADestroy @ckdt


END
GO

 

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