Amazon Simple Storage Service
Developer Guide (API Version 2006-03-01)

Generate a Pre-signed Object URL Using AWS SDK for .NET

The following example generates a pre-signed URL that you can give to others so that they can retrieve an object. For more information, see Share an Object with Others.

For instructions about how to create and test a working sample, see Running the Amazon S3 .NET Code Examples.

// Copyright 2018, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 (For details, see using Amazon.S3; using Amazon.S3.Model; using System; namespace Amazon.DocSamples.S3 { class GenPresignedURLTest { private const string bucketName = "*** bucket name ***"; private const string objectKey = "*** object key ***"; // Specify your bucket region (an example region is shown). private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2; private static IAmazonS3 s3Client; public static void Main() { s3Client = new AmazonS3Client(bucketRegion); string urlString = GeneratePreSignedURL(); } static string GeneratePreSignedURL() { string urlString = ""; try { GetPreSignedUrlRequest request1 = new GetPreSignedUrlRequest { BucketName = bucketName, Key = objectKey, Expires = DateTime.Now.AddMinutes(5) }; urlString = s3Client.GetPreSignedURL(request1); } catch (AmazonS3Exception e) { Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message); } catch (Exception e) { Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message); } return urlString; } } }