SQL Server
SQL Server
Generate S3 Signed URL
See more Amazon S3 Examples
Demonstrates how to generate a pre-signed S3 URL.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)
-- This example assumes 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
-- Insert your access key here:
EXEC sp_OASetProperty @http, 'AwsAccessKey', 'AWS_ACCESS_KEY'
-- Insert your secret key here:
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 = 'chilkattest'
DECLARE @path nvarchar(4000)
SELECT @path = 'starfish.jpg'
DECLARE @signedUrl nvarchar(4000)
EXEC sp_OAMethod @http, 'S3_GenPresignedUrl', @signedUrl OUT, 'GET', 1, @bucketName, @path, 3600, 's3'
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
RETURN
END
PRINT @signedUrl
EXEC @hr = sp_OADestroy @http
END
GO