Upload files directly to Amazon S3 from ASP.NET application

My ASP.NET MVC application will take a lot of bandwidth and storage space. How can I setup an ASP.NET upload page so the file the user uploaded will go straight to Amazon S3 without using my web server's storage and bandwidth?


Solution 1:

Update Feb 2016:

The AWS SDK can handle a lot more of this now. Check out how to build the form, and how to build the signature. That should prevent you from needing the bandwidth on your end, assuming you need to do no processing of the content yourself before sending it to S3.

Solution 2:

If you need to upload large files and display a progress bar you should consider the flajaxian component.

It uses flash to upload files directly to amazon s3, saving your bandwidth.

Solution 3:

The best and the easiest way to upload files to amazon S3 via asp.net . Have a look at following blog post by me . i think this one will help. Here i have explained from adding a S3 bucket to creating the API Key, Installing Amazon SDK and writing code to upload files. Following are are the sample code for uploading files to amazon S3 with asp.net C#.

using System
using System.Collections.Generic
using System.Linq
using System.Web
using Amazon
using Amazon.S3
using Amazon.S3.Transfer
/// 
/// Summary description for AmazonUploader
/// 
public class AmazonUploader
{
        public bool sendMyFileToS3(System.IO.Stream localFilePath, string bucketName, string subDirectoryInBucket, string fileNameInS3)
        {
        // input explained :
        // localFilePath = we will use a file stream , instead of path
        // bucketName : the name of the bucket in S3 ,the bucket should be already created
        // subDirectoryInBucket : if this string is not empty the file will be uploaded to
            // a subdirectory with this name
        // fileNameInS3 = the file name in the S3
    // create an instance of IAmazonS3 class ,in my case i choose RegionEndpoint.EUWest1
    // you can change that to APNortheast1 , APSoutheast1 , APSoutheast2 , CNNorth1
    // SAEast1 , USEast1 , USGovCloudWest1 , USWest1 , USWest2 . this choice will not
    // store your file in a different cloud storage but (i think) it differ in performance
    // depending on your location


        IAmazonS3 client = new AmazonS3Client("Your Access Key", "Your Secrete Key", Amazon.RegionEndpoint.USWest2);

    // create a TransferUtility instance passing it the IAmazonS3 created in the first step
    TransferUtility utility = new TransferUtility(client);
    // making a TransferUtilityUploadRequest instance
    TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();

    if (subDirectoryInBucket == "" || subDirectoryInBucket == null)
    {
        request.BucketName = bucketName; //no subdirectory just bucket name
    }
    else
    {   // subdirectory and bucket name
        request.BucketName = bucketName + @"/" + subDirectoryInBucket;
    }
    request.Key = fileNameInS3 ; //file name up in S3
    //request.FilePath = localFilePath; //local file name
    request.InputStream = localFilePath;
    request.CannedACL = S3CannedACL.PublicReadWrite;
    utility.Upload(request); //commensing the transfer

    return true; //indicate that the file was sent
}
}

Here you can use the function sendMyFileToS3 to upload file stream to amazon S3. For more details check my blog in the following link.

Upload File to Amazon S3 via asp.net

I hope the above mentioned link will help.

Solution 4:

Look for a javascript library to handle the client side upload of these files. I stumbled upon a javascript and php example Dojo also seems to offer a clientside s3 file upload.