Uploading a file and getting back its URL with AWS

I was playing with Amazon Web Services (AWS) over the weekend, trying out a few things including Amazon S3 for file storage. Unfortunately I could not find a quick and easy way to upload an image and retrieve its URL in single call in the AWS SDK…so I got creative

With the AmazonS3 interface from the AWS SDK, you have to make separate calls to put your object in their server and to retrieve it. To encapsulate this I wrote an extension class that performs those 2 operations.

public static class AwsExtensions
public static string Upload(this AmazonS3 client,UploadImageRequest request)
var uploadRequest = new PutObjectRequest { InputStream = request.Image };
var response = client.PutObject(uploadRequest);
return GetUrl(client, request);
public static string GetUrl(this AmazonS3 client, UploadImageRequest request)
var urlRequest = new GetPreSignedUrlRequest()
return client.GetPreSignedURL(urlRequest);

view raw
hosted with ❤ by GitHub

Et voila! Ni vu, ni connu

Uploading a file and getting back its URL with AWS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s