Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
Amazon S3 - Create Bucket with ConstraintCreate an Amazon S3 bucket with a constraint using the REST API.
CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int DECLARE @sTmp0 nvarchar(4000) DECLARE @http int EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @http, 'UnlockComponent', @success OUT, 'Anything for 30-day trial.' IF @success <> 1 BEGIN -- Unlock failed. EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Create the XML contraint for the bucket: -- <CreateBucketConfiguration> -- <LocationConstraint>EU</LocationConstraint> -- </CreateBucketConfiguration> DECLARE @xml int EXEC @hr = sp_OACreate 'Chilkat.Xml', @xml OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OASetProperty @xml, 'Tag', 'CreateBucketConfiguration' EXEC sp_OAMethod @xml, 'NewChild2', NULL, 'LocationConstraint', 'EU' EXEC sp_OAMethod @xml, 'GetXml', @sTmp0 OUT PRINT @sTmp0 DECLARE @crypt int EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OAMethod @crypt, 'UnlockComponent', @success OUT, 'Anything for 30-day trial.' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @crypt, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- The HTTP component now includes a method to generate -- the current date/time in RFC 2616 compliant format. -- Note: The GenTimeStamp method is available as a pre-release (as of 18-June-2008). -- It will become available in the next new version dated after -- 18-June-2008. DECLARE @curDateTime nvarchar(4000) EXEC sp_OAMethod @http, 'GenTimeStamp', @curDateTime OUT -- The PUT request operation with a bucket URI creates a new bucket. DECLARE @strToSign nvarchar(4000) ERROR-CONCAT SELECT @strToSign = 'PUT' + CHAR(10) + CHAR(10) + 'text/xml' + CHAR(10) + @curDateTime + CHAR(10) + '/chilkat2/' -- We want SHA1 for the HMAC hash algorithm: EXEC sp_OASetProperty @crypt, 'HashAlgorithm', 'sha1' -- These must be changed for your account: DECLARE @AWSAccessKeyId nvarchar(4000) SELECT @AWSAccessKeyId = 'zzzzzzzzzzzzzzzzzzzz' DECLARE @AWSSecretAccessKey nvarchar(4000) SELECT @AWSSecretAccessKey = 'zzzzzzzzzzzzzzzzzzzzzzzzzz' -- Set the HMAC secret key: EXEC sp_OAMethod @crypt, 'SetHmacKeyString', NULL, @AWSSecretAccessKey -- By setting the charset = "utf-8", the string will be converted -- to utf-8 (internal to the Chilkat component) prior to signing: EXEC sp_OASetProperty @crypt, 'Charset', 'utf-8' -- Indicate that Base64 output is desired: EXEC sp_OASetProperty @crypt, 'EncodingMode', 'base64' DECLARE @signature nvarchar(4000) EXEC sp_OAMethod @crypt, 'HmacStringENC', @signature OUT, @strToSign DECLARE @authValue nvarchar(4000) ERROR-CONCAT SELECT @authValue = 'AWS ' + @AWSAccessKeyId + ':' + @signature -- The bucket to be created is specified in the Host header. -- In this example, the "chilkat2" bucket is created: EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Host', 'chilkat2.s3.amazonaws.com' EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', @authValue EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Date', @curDateTime DECLARE @xmlResponse nvarchar(4000) EXEC sp_OAMethod @xml, 'GetXml', @sTmp0 OUT EXEC sp_OAMethod @http, 'XmlRpcPut', @xmlResponse OUT, 'http://s3.amazonaws.com/', @sTmp0 IF @xmlResponse Is NULL BEGIN PRINT 'NULL response' PRINT '---' -- Failed. Show the last request header, response header, -- and response body. EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT PRINT @sTmp0 PRINT '---' EXEC sp_OAGetProperty @http, 'LastResponseHeader', @sTmp0 OUT PRINT @sTmp0 PRINT '---' EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 END ELSE BEGIN -- Success is indicated by an empty xmlResponse string, and -- a response status of 200. EXEC sp_OAGetProperty @http, 'LastStatus', @sTmp0 OUT IF @sTmp0 = 200 BEGIN PRINT 'Bucket created!' -- Let's check out the response header anyway... EXEC sp_OAGetProperty @http, 'LastResponseHeader', @sTmp0 OUT PRINT @sTmp0 END ELSE BEGIN EXEC sp_OAGetProperty @http, 'LastStatus', @iTmp0 OUT PRINT 'LastStatus: ' + @iTmp0 PRINT '---' -- Failed. Show the last request header, response header, -- and response body. EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT PRINT @sTmp0 PRINT '---' EXEC sp_OAGetProperty @http, 'LastResponseHeader', @sTmp0 OUT PRINT @sTmp0 PRINT '---' EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 END END END GO |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.