Last active
December 18, 2015 21:19
-
-
Save bhameyie/5846874 to your computer and use it in GitHub Desktop.
File Upload with Url retrieval using AWS S3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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