本文整理汇总了C#中Amazon.S3.AmazonS3Client类的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3Client类的具体用法?C# AmazonS3Client怎么用?C# AmazonS3Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AmazonS3Client类属于Amazon.S3命名空间,在下文中一共展示了AmazonS3Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadDataFileAsync
public async Task UploadDataFileAsync(string data, string storageKeyId, string storageSecret, string region)
{
var regionIdentifier = RegionEndpoint.GetBySystemName(region);
using (var client = new AmazonS3Client(storageKeyId, storageSecret, regionIdentifier))
{
try
{
var putRequest1 = new PutObjectRequest
{
BucketName = AwsBucketName,
Key = AwsBucketFileName,
ContentBody = data,
ContentType = "application/json"
};
await client.PutObjectAsync(putRequest1);
}
catch (AmazonS3Exception amazonS3Exception)
{
if (amazonS3Exception.ErrorCode != null &&
(amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
{
throw new SecurityException("Invalid Amazon S3 credentials - data was not uploaded.", amazonS3Exception);
}
throw new HttpRequestException("Unspecified error attempting to upload data: " + amazonS3Exception.Message, amazonS3Exception);
}
var response = await client.GetObjectAsync(AwsBucketName, AwsBucketFileName);
using (var reader = new StreamReader(response.ResponseStream))
{
Debug.WriteLine(await reader.ReadToEndAsync());
}
}
}
示例2: SendImageToS3
public static Boolean SendImageToS3(String key, Stream imageStream)
{
var success = false;
using (var client = new AmazonS3Client(RegionEndpoint.USWest2))
{
try
{
PutObjectRequest request = new PutObjectRequest()
{
InputStream = imageStream,
BucketName = BucketName,
Key = key
};
client.PutObject(request);
success = true;
}
catch (Exception ex)
{
// swallow everything for now.
}
}
return success;
}
示例3: ImportIntoS3Tasks
public ImportIntoS3Tasks()
{
appHost = new BasicAppHost().Init();
var s3Client = new AmazonS3Client(AwsConfig.AwsAccessKey, AwsConfig.AwsSecretKey, RegionEndpoint.USEast1);
s3 = new S3VirtualPathProvider(s3Client, AwsConfig.S3BucketName, appHost);
}
示例4: S3TraceListener
public S3TraceListener(string initializeData)
{
string[] commands = initializeData.Split(',');
foreach (var command in commands)
{
string[] subcommand = command.Split('=');
switch (subcommand[0])
{
case "logfile":
LogFileName = string.Format("{0}.{1}.log", GetUnixTime(), subcommand[1]);
break;
case "bucket":
_bucketName = subcommand[1];
break;
}
}
if (LogFileName == null || _bucketName == null)
{
throw new Exception("Not valid parameters. Pass logfile=,bucketname=.");
}
if (_amazonConfig == null)
{
_amazonConfig = new EnvironmentAWSCredentials();
_s3Client = new AmazonS3Client(_amazonConfig);
_stringFile = new List<string>();
}
}
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (upload.PostedFile != null && upload.PostedFile.ContentLength > 0 && !string.IsNullOrEmpty(Request["awsid"]) && !string.IsNullOrEmpty(Request["awssecret"]) && !string.IsNullOrEmpty(this.bucket.Text))
{
var name = "s3readersample/" + ImageUploadHelper.Current.GenerateSafeImageName(upload.PostedFile.InputStream, upload.PostedFile.FileName);
var client = new Amazon.S3.AmazonS3Client(Request["awsid"], Request["awssecret"], Amazon.RegionEndpoint.EUWest1);
//For some reason we have to buffer the file in memory to prevent issues... Need to research further
var ms = new MemoryStream();
upload.PostedFile.InputStream.CopyTo(ms);
ms.Seek(0, SeekOrigin.Begin);
var request = new Amazon.S3.Model.PutObjectRequest() { BucketName = this.bucket.Text, Key = name, InputStream = ms, CannedACL = Amazon.S3.S3CannedACL.PublicRead };
var response = client.PutObject(request);
if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
{
result.Text = "Successfully uploaded " + name + "to bucket " + this.bucket.Text;
}
else
{
result.Text = response.HttpStatusCode.ToString();
}
}
}
示例6: S3Reader2
public S3Reader2(NameValueCollection args )
{
s3config = new AmazonS3Config();
buckets = args["buckets"];
vpath = args["prefix"];
asVpp = NameValueCollectionExtensions.Get(args, "vpp", true);
Region = args["region"] ?? "us-east-1";
s3config.UseHttp = !NameValueCollectionExtensions.Get(args, "useSsl", false);
if (!string.IsNullOrEmpty(args["accessKeyId"]) && !string.IsNullOrEmpty(args["secretAccessKey"])) {
S3Client = new AmazonS3Client(args["accessKeyId"], args["secretAccessKey"], s3config);
} else {
S3Client = new AmazonS3Client(null, s3config);
}
includeModifiedDate = NameValueCollectionExtensions.Get(args, "includeModifiedDate", includeModifiedDate);
includeModifiedDate = NameValueCollectionExtensions.Get(args, "checkForModifiedFiles", includeModifiedDate);
RequireImageExtension = NameValueCollectionExtensions.Get(args, "requireImageExtension", RequireImageExtension);
UntrustedData = NameValueCollectionExtensions.Get(args, "untrustedData", UntrustedData);
CacheUnmodifiedFiles = NameValueCollectionExtensions.Get(args, "cacheUnmodifiedFiles", CacheUnmodifiedFiles);
}
示例7: DeleteFile
public void DeleteFile(String filename)
{
String key = filename;
var amazonClient = new AmazonS3Client(_keyPublic, _keySecret);
var deleteObjectRequest = new DeleteObjectRequest { BucketName = _bucket, Key = key };
var response = amazonClient.DeleteObject(deleteObjectRequest);
}
示例8: GetComputeNode
public IComputeNode GetComputeNode()
{
IComputeNode compute_node = null;
try
{
//amazon client
using (var client = new AmazonS3Client())
{
//download request
using (var response = client.GetObject(new GetObjectRequest()
.WithBucketName(AmazonBucket)
.WithKey(BermudaConfig)))
{
using (StreamReader reader = new StreamReader(response.ResponseStream))
{
//read the file
string data = reader.ReadToEnd();
//deserialize
compute_node = new ComputeNode().DeserializeComputeNode(data);
if(compute_node.Catalogs.Values.Cast<ICatalog>().FirstOrDefault().CatalogMetadata.Tables.FirstOrDefault().Value.DataType == null)
compute_node.Catalogs.Values.Cast<ICatalog>().FirstOrDefault().CatalogMetadata.Tables.FirstOrDefault().Value.DataType = typeof(UDPTestDataItems);
compute_node.Init(CurrentInstanceIndex, AllNodeEndpoints.Count());
}
}
}
}
catch (Exception ex)
{
Trace.WriteLine(ex.ToString());
}
return compute_node;
}
示例9: CreateAndCheckTestBucket
private void CreateAndCheckTestBucket()
{
TestBucketIsReady = false;
USEast1Client = new AmazonS3Client(RegionEndpoint.USEast1);
USWest1Client = new AmazonS3Client(RegionEndpoint.USWest1);
var sessionCredentials = new AmazonSecurityTokenServiceClient().GetSessionToken().Credentials;
USEast1ClientWithSessionCredentials = new AmazonS3Client(sessionCredentials, RegionEndpoint.USEast1);
TestBucket = USWest1Client.ListBuckets().Buckets.Find(bucket => bucket.BucketName.StartsWith(BucketPrefix));
if (TestBucket == null)
{
// add ticks to bucket name because the bucket namespace is shared globally
var bucketName = BucketPrefix + DateTime.Now.Ticks;
// Create the bucket but don't run the test.
// If the bucket is ready the next time this test runs we'll test then.
USWest1Client.PutBucket(new PutBucketRequest()
{
BucketRegion = S3Region.USW1,
BucketName = bucketName,
});
}
else if (TestBucket.CreationDate.AddHours(TemporaryRedirectMaxExpirationHours) < DateTime.Now)
{
BucketRegionDetector.BucketRegionCache.Clear();
TestBucketIsReady = true;
}
}
示例10: GetTargetAppVersion
public Guid? GetTargetAppVersion(Guid targetKey, Guid appKey)
{
try
{
using (var client = new AmazonS3Client(Context.AwsAccessKeyId, Context.AwsSecretAccessKey))
{
using (var res = client.GetObject(new GetObjectRequest()
{
BucketName = Context.BucketName,
Key = GetTargetAppVersionInfoPath(targetKey, appKey),
}))
{
using (var stream = res.ResponseStream)
{
return Utils.Serialisation.ParseKey(stream);
}
}
}
}
catch (AmazonS3Exception awsEx)
{
if (awsEx.StatusCode == System.Net.HttpStatusCode.NotFound)
{
return null;
}
else
{
throw new DeploymentException(string.Format("Failed getting version for app with key \"{0}\" and target with the key \"{1}\".", appKey, targetKey), awsEx);
}
}
}
示例11: Start
// Use this for initialization
void Start () {
// ResultText is a label used for displaying status information
Debug.Log("hallo1");
Debug.Log("hallo2");
S3Client = new AmazonS3Client(Credentials);
Debug.Log("hallo3");
ResultText.text = "Fetching all the Buckets";
S3Client.ListBucketsAsync(new ListBucketsRequest(), (responseObject) =>
{
ResultText.text += "\n";
if (responseObject.Exception == null)
{
ResultText.text += "Got Response \nPrinting now \n";
responseObject.Response.Buckets.ForEach((s3b) =>
{
ResultText.text += string.Format("bucket = {0}, created date = {1} \n",
s3b.BucketName, s3b.CreationDate);
});
}
else
{
ResultText.text += "Got Exception \n";
}
});
}
示例12: TestSerializingExceptions
public void TestSerializingExceptions()
{
using(var client = new Amazon.S3.AmazonS3Client())
{
try
{
var fakeBucketName = "super.duper.fake.bucket.name.123." + Guid.NewGuid().ToString();
client.ListObjects(fakeBucketName);
}
catch(AmazonS3Exception e)
{
TestException(e);
}
var s3pue = CreateS3PostUploadException();
TestException(s3pue);
var doe = CreateDeleteObjectsException();
TestException(doe);
var aace = new AdfsAuthenticationControllerException("Message");
TestException(aace);
#pragma warning disable 618
var ccre = new CredentialCallbackRequiredException("Message");
TestException(ccre);
var afe = new AuthenticationFailedException("Message");
TestException(afe);
#pragma warning restore 618
}
}
示例13: DeleteObjectList
/// <summary>AWS S3 여러 객체 삭제</summary>
public DeleteObjectsResponse DeleteObjectList(List<string> pKeyList)
{
try
{
using (AmazonS3Client client = new AmazonS3Client())
{
DeleteObjectsRequest multiObjectDeleteRequest = new DeleteObjectsRequest();
multiObjectDeleteRequest.BucketName = strAwsBucketName;
foreach (string key in pKeyList)
{
multiObjectDeleteRequest.AddKey(key);
}
DeleteObjectsResponse response = client.DeleteObjects(multiObjectDeleteRequest);
//response.DeleteErrors.Count = 실패한 삭제 객체
//response.DeletedObjects.Count = 성공한 삭제 객체
//.Key, .Code, .Message로 정보 확인 가능.
return response;
}
}
catch (AmazonS3Exception amazonS3Exception)
{
throw amazonS3Exception;
}
}
示例14: EnvioS3
public EnvioS3(StringBuilder log, string arquivo, string accessKey, string secretKey, string bucketName)
{
_log = log;
_arquivo = arquivo;
_bucketName = bucketName;
_client = new AmazonS3Client(accessKey, secretKey);
}
示例15: TestPostUpload
public void TestPostUpload()
{
var region = RegionEndpoint.USWest1;
using (var client = new AmazonS3Client(region))
{
var bucketName = S3TestUtils.CreateBucket(client);
client.PutACL(new PutACLRequest
{
BucketName = bucketName,
CannedACL = S3CannedACL.BucketOwnerFullControl
});
var credentials = GetCredentials(client);
try
{
var response = testPost("foo/bar/content.txt", bucketName, testContentStream("Line one\nLine two\nLine three\n"), "", credentials, region);
Assert.IsNotNull(response.RequestId);
Assert.IsNotNull(response.HostId);
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
finally
{
AmazonS3Util.DeleteS3BucketWithObjects(client, bucketName);
}
}
}