Sample code for 30+ languages & platforms
SQL Server

Example: Http.S3_FileExists method

Demonstrates the S3_FileExists method.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    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

    -- Insert your AWS keys here:
    EXEC sp_OASetProperty @http, 'AwsAccessKey', 'AWS_ACCESS_KEY'
    EXEC sp_OASetProperty @http, 'AwsSecretKey', 'AWS_SECRET_KEY'

    DECLARE @bucketName nvarchar(4000)
    SELECT @bucketName = 'chilkat.ocean'
    DECLARE @objectName nvarchar(4000)
    SELECT @objectName = 'seahorse.jpg'
    EXEC sp_OASetProperty @http, 'AwsRegion', 'us-west-2'
    EXEC sp_OASetProperty @http, 'AwsEndpoint', 's3-us-west-2.amazonaws.com'

    DECLARE @retval int
    EXEC sp_OAMethod @http, 'S3_FileExists', @retval OUT, @bucketName, @objectName
    IF @retval < 0
      BEGIN

        PRINT 'Failed to check for the S3 object existence'
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        RETURN
      END
    IF @retval = 0
      BEGIN

        PRINT 'The S3 object does not exist.'
        EXEC @hr = sp_OADestroy @http
        RETURN
      END


    PRINT 'The S3 object exists.'

    EXEC @hr = sp_OADestroy @http


END
GO