Skip to content

Instantly share code, notes, and snippets.

@bhameyie
Last active December 18, 2015 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhameyie/5846874 to your computer and use it in GitHub Desktop.
Save bhameyie/5846874 to your computer and use it in GitHub Desktop.
File Upload with Url retrieval using AWS S3
public static class AwsExtensions
{
public static string Upload(this AmazonS3 client,UploadImageRequest request)
{
var uploadRequest = new PutObjectRequest { InputStream = request.Image };
uploadRequest.WithBucketName(request.Bucket).WithKey(request.FileIdentifier);
var response = client.PutObject(uploadRequest);
return GetUrl(client, request);
}
public static string GetUrl(this AmazonS3 client, UploadImageRequest request)
{
var urlRequest = new GetPreSignedUrlRequest()
.WithBucketName(request.Bucket)
.WithKey(request.FileIdentifier)
.WithProtocol(Protocol.HTTP)
.WithExpires(DateTime.Now.AddMinutes(30));
return client.GetPreSignedURL(urlRequest);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment