-
-
Save ntulip/640901 to your computer and use it in GitHub Desktop.
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
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