SQL Server
SQL Server
Example: Http.S3_DownloadBd method
See more Amazon S3 Examples
Demonstrates theS3_DownloadBd method.
Chilkat SQL Server Downloads
-- 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)
DECLARE @success int
SELECT @success = 0
-- This requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @http, 'AwsAccessKey', 'AWS_ACCESS_KEY'
EXEC sp_OASetProperty @http, 'AwsSecretKey', 'AWS_SECRET_KEY'
EXEC sp_OASetProperty @http, 'AwsRegion', 'us-west-2'
EXEC sp_OASetProperty @http, 'AwsEndpoint', 's3-us-west-2.amazonaws.com'
DECLARE @bucketName nvarchar(4000)
SELECT @bucketName = 'chilkat.qa'
DECLARE @objectName nvarchar(4000)
SELECT @objectName = '/images/sea_creatures/starfish.jpg'
DECLARE @localFilePath nvarchar(4000)
SELECT @localFilePath = 'qa_output/starfish.jpg'
DECLARE @bd int
EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT
EXEC sp_OAMethod @http, 'S3_DownloadBd', @success OUT, @bucketName, @objectName, @bd
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @bd
RETURN
END
EXEC sp_OAGetProperty @bd, 'NumBytes', @iTmp0 OUT
PRINT 'Downloaded ' + @iTmp0 + ' bytes'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @bd
END
GO