Click here to Skip to main content
12,558,319 members (60,954 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


8 bookmarked

Store Files in Amazon S3 using AWS SDK in ASP.NET MVC

, 8 Feb 2015 CPOL
Rate this:
Please Sign up or sign in to vote.
Store files in Amazon S3 using AWS SDK in ASP.NET MVC

In this article, we will learn how to store files in Amazon S3 using AWS SDK in ASP.NET MVC.

Check here how to Upload Base64 data to S3 using AWS SDK in ASP.NET MVC.

What is Amazon S3

Amazon S3 (Simple Storage Service) is an online file storage web service offered by Amazon Web Services. The S3 allows uploading, storage and downloading of practically any file or object up to five gigabytes (5 GB) in size. To use Amazon S3, we must create a bucket to the store data. Each Buckets have the configuration properties like to make the objects accesses public or private.

Step 1: Install Amazon AWS SDK

To install AWS SDK for .NET, run the following command in the Package Manager Console.

Install-Package AWSSDK

Step 2: Get your Access Key ID and Secret Access Key

To use AWS SDK, first you need to get your Access Key ID and Secret Access Key. You can create using the IAM console to know more about how create your access keys. Please check the following documentation at Amazon:

Step 3: Create Bucket

Here, we can create the bucket using AWS Console.

S3 Management Console

S3 Management Console

Once the bucket is created save the bucket name in the web.config file. 
Also save your AWSAccessKey and AWSSecretKey in the web.config file.

Step 4: Using AWS SDK.Net

Upload a file using form post use the following code:

A bucket can have multiple keys. A Key can store multiple objects. In simple words, Key is folder name. Here, we are using the Key name as UPLOADS.

using System;
using System.Configuration;
using System.Web;
using System.Web.Mvc;
using Amazon;
using Amazon.S3;
using Amazon.S3.Model;

namespace AmazonAWS.Controllers
    public class S3Controller : Controller
        private static readonly string _awsAccessKey = 

        private static readonly string _awsSecretKey = 

        private static readonly string _bucketName = 

        public ActionResult UploadToS3(HttpPostedFileBase file)
                IAmazonS3 client;
                using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(_awsAccessKey, _awsSecretKey))
                    var request = new PutObjectRequest()
                        BucketName = _bucketName,
                        CannedACL = S3CannedACL.PublicRead,//PERMISSION TO FILE PUBLIC ACCESIBLE
                        Key =  string.Format("UPLOADS/{0}", file.FileName),
                        InputStream = file.InputStream//SEND THE FILE STREAM

            catch (Exception ex)

            return View();

The post Store files in Amazon S3 using AWS SDK in ASP.NET MVC appeared first on Venkat Baggu Blog.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) eBiz Solutions
India India
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161026.1 | Last Updated 9 Feb 2015
Article Copyright 2015 by madan535
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid