Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Delphi DLL Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Google APIs
Google Calendar
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
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Delphi DLL) Azure Storage: Upload Binary Data to Block Blob

Sample code to upload binary bytes to a block blob in Azure Cloud Storage. This creates the block blob, or replaces an existing block blob.

Note: The maximum size of a block blob created by uploading in a single step is 64MB. For larger files, the upload must be broken up into blocks. There is another Chilkat example for that..

Chilkat for Delphi Downloads

Chilkat non-ActiveX DLL for Delphi

Chilkat ActiveX DLL for Delphi

* The examples here use the non-ActiveX DLL.

uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, FileAccess, Rest, AuthAzureStorage, CkByteData;

...

procedure TForm1.Button1Click(Sender: TObject);
var
rest: HCkRest;
bTls: Boolean;
port: Integer;
bAutoReconnect: Boolean;
success: Boolean;
azAuth: HCkAuthAzureStorage;
binaryData: HCkByteData;
fac: HCkFileAccess;
responseStr: PWideChar;

begin
//  Azure Blob Service Example: Upload binary bytes to a block blob.
//  This creates a new block blob or replaces an existing one in its entirety.
//  See also: https://msdn.microsoft.com/en-us/library/azure/dd179451.aspx

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

rest := CkRest_Create();

//  Connect to the Azure Storage Blob Service
bTls := True;
port := 443;
bAutoReconnect := True;
//  In this example, the storage account name is "chilkat".
success := CkRest_Connect(rest,'chilkat.blob.core.windows.net',port,bTls,bAutoReconnect);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

//  Provide Azure Cloud credentials for the REST call.
azAuth := CkAuthAzureStorage_Create();
CkAuthAzureStorage_putAccessKey(azAuth,'AZURE_ACCESS_KEY');
//  The account name used here should match the 1st part of the domain passed in the call to Connect (above).
CkAuthAzureStorage_putAccount(azAuth,'chilkat');
CkAuthAzureStorage_putScheme(azAuth,'SharedKey');
CkAuthAzureStorage_putService(azAuth,'Blob');
//  This causes the "x-ms-version: 2015-02-21" header to be automatically added.
CkAuthAzureStorage_putXMsVersion(azAuth,'2015-02-21');
success := CkRest_SetAuthAzureStorage(rest,azAuth);

//  Note: The application does not need to explicitly set the following
//  headers: Content-Length, x-ms-date, Authorization.  These headers
//  are automatically set by Chilkat.

//  IMPORTANT: Make sure to set the x-ms-blob-type header:
success := CkRest_AddHeader(rest,'x-ms-blob-type','BlockBlob');

//  For this example, we'll just load a JPG file into memory..
binaryData := CkByteData_Create();
fac := CkFileAccess_Create();
success := CkFileAccess_ReadEntireFile(fac,'qa_data/jpg/starfish.jpg',binaryData);

// Note: The maximum size of a block blob created by uploading in a single step is 64MB.
// For larger files, the upload must be broken up into blocks.  There is another Chilkat example for that..
responseStr := CkRest__fullRequestBinary(rest,'PUT','/mycontainer/starfish.jpg',binaryData);
if (CkRest_getLastMethodSuccess(rest) <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

//  When successful, the Azure Storage service will respond with a 201 response status code,
//  with no response body.

if (CkRest_getResponseStatusCode(rest) <> 201) then
  begin
    //  Examine the request/response to see what happened.
    Memo1.Lines.Add('response status code = ' + IntToStr(CkRest_getResponseStatusCode(rest)));
    Memo1.Lines.Add('response status text = ' + CkRest__responseStatusText(rest));
    Memo1.Lines.Add('response header: ' + CkRest__responseHeader(rest));
    Memo1.Lines.Add('response body (if any): ' + responseStr);
    Memo1.Lines.Add('---');
    Memo1.Lines.Add('LastRequestStartLine: ' + CkRest__lastRequestStartLine(rest));
    Memo1.Lines.Add('LastRequestHeader: ' + CkRest__lastRequestHeader(rest));
    Exit;
  end;

Memo1.Lines.Add('Success.');

CkRest_Dispose(rest);
CkAuthAzureStorage_Dispose(azAuth);
CkByteData_Dispose(binaryData);
CkFileAccess_Dispose(fac);

end;

 

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