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

C 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
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
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
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

 

 

 

(C) Create S3 Bucket in a Region

Demonstrates how to create an S3 bucket in a specified region. This example will create a bucket in the eu-west-2 region.

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Win Mobile 5.0/Pocket PC 2003

Solaris C/C++

FreeBSD C/C++

OpenBSD C/C++

MinGW C/C++

#include <C_CkRest.h>
#include <C_CkAuthAws.h>
#include <C_CkXml.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    BOOL success;
    HCkAuthAws authAws;
    HCkXml xml;
    const char *responseStr;
    HCkXml responseXml;

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

    rest = CkRest_Create();

    //  Connect to the Amazon AWS REST server.
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRest_Connect(rest,"s3.amazonaws.com",port,bTls,bAutoReconnect);

    //  Provide AWS credentials for the REST call.
    authAws = CkAuthAws_Create();
    CkAuthAws_putAccessKey(authAws,"AWS_ACCESS_KEY");
    CkAuthAws_putSecretKey(authAws,"AWS_SECRET_KEY");
    CkAuthAws_putServiceName(authAws,"s3");
    success = CkRest_SetAuthAws(rest,authAws);

    //  We'll send a PUT request having an XML body such as this:
    //  <CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    //    <LocationConstraint>BucketRegion</LocationConstraint>
    //    </CreateBucketConfiguration>

    //  Create the XML body specifying the region as "eu-west-2"
    xml = CkXml_Create();
    CkXml_putTag(xml,"CreateBucketConfiguration");
    CkXml_AddAttribute(xml,"xmlns","http://s3.amazonaws.com/doc/2006-03-01/");
    CkXml_UpdateChildContent(xml,"LocationConstraint","eu-west-2");

    //  Set the bucket name via the HOST header.
    //  In this case, the bucket name is "chilkateuwest2".
    CkRest_putHost(rest,"chilkateuwest2.s3.amazonaws.com");

    //  Make the call to create the bucket.
    responseStr = CkRest_fullRequestString(rest,"PUT","/",CkXml_getXml(xml));
    if (CkRest_getLastMethodSuccess(rest) != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkAuthAws_Dispose(authAws);
        CkXml_Dispose(xml);
        return;
    }

    if (CkRest_getResponseStatusCode(rest) != 200) {
        printf("status code = %d\n",CkRest_getResponseStatusCode(rest));
        responseXml = CkXml_Create();
        CkXml_LoadXml(responseXml,responseStr);
        printf("%s\n",CkXml_getXml(responseXml));
        printf("Failed.\n");
        CkRest_Dispose(rest);
        CkAuthAws_Dispose(authAws);
        CkXml_Dispose(xml);
        CkXml_Dispose(responseXml);
        return;
    }

    printf("Bucket in the eu-west-2 region created.\n");


    CkRest_Dispose(rest);
    CkAuthAws_Dispose(authAws);
    CkXml_Dispose(xml);
    CkXml_Dispose(responseXml);

    }

 

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