Skip to content

Instantly share code, notes, and snippets.

@gorsuch
Created June 16, 2010 14:52
Show Gist options
  • Save gorsuch/440807 to your computer and use it in GitHub Desktop.
Save gorsuch/440807 to your computer and use it in GitHub Desktop.
Uploading to S3 via C#
using System;
using System.IO;
using System.Text;
using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
namespace AWSUploadTest
{
class Program
{
public static void Main(string[] args)
{
// basic params
string accessKey = "mykey";
string secretAccessKey = "mysecret";
string bucketName = "mybucket";
string keyName = "test.txt";
string sourceFileName = @"c:\temp\upload.txt";
// initialize our client
AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey, secretAccessKey);
// initialize our request
PutObjectRequest request = new PutObjectRequest();
// we'll use a stream so we can efficiently handle files large or small
FileStream fs = new FileStream(sourceFileName, FileMode.Open);
// setup the request
request.WithInputStream(fs);
request.WithBucketName(bucketName);
request.WithKey(keyName);
// do it!
client.PutObject(request);
// fin!
fs.Close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment