Upload images to Amazon S3 buckets in c#
The main advantage of uploading files to Amazon S3(Simple Storage Service) is reduces the loading time of site and also uploading is qiute simple.This article describes about uploading images to amazon S3.
Amazon S3 is using Cloud hosting and image serving is relatively fast. one of the main advantages of using Amazon S3 is serving static images and files via more efficient content delivery network of Amazon.
For uploading to Amazon S3,first Create a Bucket for images.Upload images to your Bucket. Your data is durably stored and backed by the Amazon S3 Service
Name space Using:
using Amazon.S3.Model;
using Amazon.S3;
using Amazon;
Write the code in the upload button click.
AmazonS3 client = AWSClientFactory.CreateAmazonS3Client("Access Key", "Acess secrete key");
var request = new PutObjectRequest();
request.WithBucketName("BucketName");
request.WithKey(file.Filename);
request.FilePath = filePath;
request.ContentType = file.ContentType;
request.StorageClass = S3StorageClass.Standard;
request.CannedACL = S3CannedACL.BucketOwnerFullControl;
client.PutObject(request);
In addition to this We can want to add metadata for images. the metadata contain detail information about the images such as
type of images,date of images create,accessed,modified etc.
if we want to add metadata for the uploading images
then add these code too before calling client.PutObject(request).
request.AddHeader("Expires", "Fri, Apr 23 2021 10:18:36 GMT");
request.AddHeader("Cache-Control", "public");
If we want to add metadata for existing images then right click on the images and take properties,from there we can add this.