-
Notifications
You must be signed in to change notification settings - Fork 0
/
AWSUploader.cs
30 lines (29 loc) · 985 Bytes
/
AWSUploader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using Amazon.S3;
using Amazon.S3.Transfer;
using log4net;
using System.Configuration;
using System.IO;
namespace Scytale
{
class AWSUploader
{
private static readonly ILog Log = LogManager.GetLogger(typeof(AWSUploader));
string bucketName = ConfigurationManager.AppSettings["AWSBucket"];
string keyName = ConfigurationManager.AppSettings["AWSAccessKey"];
public void Upload(string filePath)
{
try
{
TransferUtility fileTransferUtility = new TransferUtility(new AmazonS3Client(Amazon.RegionEndpoint.USEast1));
using (FileStream fileToUpload = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
fileTransferUtility.Upload(fileToUpload, bucketName, keyName);
}
}
catch (AmazonS3Exception ex)
{
Log.Error(ex.Message, ex.InnerException);
}
}
}
}