本文整理汇总了C#中Amazon.S3.AmazonS3Client.PutBucket方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3Client.PutBucket方法的具体用法?C# AmazonS3Client.PutBucket怎么用?C# AmazonS3Client.PutBucket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amazon.S3.AmazonS3Client
的用法示例。
在下文中一共展示了AmazonS3Client.PutBucket方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestLocation
public void TestLocation()
{
foreach (var location in new S3Region[] { S3Region.USW1, S3Region.EUC1 })
{
string bucketName = null;
var region = RegionEndpoint.GetBySystemName(location.Value);
using (var client = new AmazonS3Client(region))
{
try
{
bucketName = UtilityMethods.SDK_TEST_PREFIX + DateTime.Now.Ticks;
client.PutBucket(new PutBucketRequest
{
BucketName = bucketName,
BucketRegion = location
});
var returnedLocation = client.GetBucketLocation(new GetBucketLocationRequest
{
BucketName = bucketName
}).Location;
Assert.AreEqual(location, returnedLocation);
}
finally
{
if (bucketName != null)
AmazonS3Util.DeleteS3BucketWithObjects(client, bucketName);
}
}
}
}
示例2: CreateBucket
public virtual void CreateBucket(AmazonS3Client s3Client, string bucketName)
{
// Create the request
var putBucketRequest = new PutBucketRequest
{
BucketName = bucketName,
UseClientRegion = true
};
// Create the bucket
s3Client.PutBucket(putBucketRequest);
}
示例3: CreateBucket
public static void CreateBucket(string name)
{
using (var client = new AmazonS3Client(Settings.AccessKey, Settings.Secret))
{
var request = new PutBucketRequest
{
BucketName = name,
BucketRegionName = Settings.Region
};
client.PutBucket(request);
}
}
示例4: ActivateOptions
public override void ActivateOptions()
{
var client = new AmazonS3Client();
ListBucketsResponse response = client.ListBuckets();
bool found = response.Buckets.Any(bucket => bucket.BucketName == BucketName);
if (found == false)
{
client.PutBucket(new PutBucketRequest().WithBucketName(BucketName));
}
base.ActivateOptions();
}
示例5: Random
//.........这里部分代码省略.........
{
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName);
blockBlob.UploadFromStream(memoryStream);
}
}
catch (Exception e)
{
}
end = DateTime.UtcNow;//////////////////////////////////////
logger.Log("End Stream Append");
}
if (syncDirection == SynchronizeDirection.Download)
{
logger.Log("Start Stream Get");
logger.Log("Start Stream GetAll");
try
{
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName);
byte[] blobContents = blockBlob.DownloadByteArray();
//if (File.Exists(blobName))
// File.Delete(blobName);
begin = DateTime.UtcNow;//////////////////////////////////////
// using (FileStream fs = new FileStream(blobName, FileMode.OpenOrCreate))
// {
byte[] contents = blockBlob.DownloadByteArray();
// fs.Write(contents, 0, contents.Length);
// }
}
catch (Exception e)
{
}
end = DateTime.UtcNow;//////////////////////////////////////
logger.Log("End Stream Get");
logger.Log("End Stream GetAll");
}
#endregion
}
else if (synchronizerType == SynchronizerType.AmazonS3)
{
#region amazon s3 stuff
if (containerName == null)
containerName = "testingraw";
if (blobName == null)
blobName = Guid.NewGuid().ToString();
AmazonS3Client amazonS3Client = new AmazonS3Client(accountName, accountKey);
if (syncDirection == SynchronizeDirection.Upload)
{
ListBucketsResponse response = amazonS3Client.ListBuckets();
foreach (S3Bucket bucket in response.Buckets)
{
if (bucket.BucketName == containerName)
{
break;
}
}
amazonS3Client.PutBucket(new PutBucketRequest().WithBucketName(containerName));
begin = DateTime.UtcNow;//////////////////////////////////////
MemoryStream ms = new MemoryStream();
ms.Write(input, 0, input.Length);
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(containerName);
request.WithKey(blobName);
request.InputStream = ms;
amazonS3Client.PutObject(request);
end = DateTime.UtcNow;//////////////////////////////////////
}
if (syncDirection == SynchronizeDirection.Download)
{
if (File.Exists(blobName))
File.Delete(blobName);
begin = DateTime.UtcNow;//////////////////////////////////////
GetObjectRequest request = new GetObjectRequest();
request.WithBucketName(containerName);
request.WithKey(blobName);
GetObjectResponse response = amazonS3Client.GetObject(request);
var localFileStream = File.Create(blobName);
response.ResponseStream.CopyTo(localFileStream);
localFileStream.Close();
end = DateTime.UtcNow;//////////////////////////////////////
}
#endregion
}
else
{
throw new InvalidDataException("syncronizer type is not valid");
}
return (end - begin).TotalMilliseconds;// return total time to upload in milliseconds
}
示例6: PrepMode_CreateBucket
public virtual void PrepMode_CreateBucket(AmazonS3Client s3Client, string bucketName)
{
var putBucketRequest = new PutBucketRequest {BucketName = bucketName, UseClientRegion = true};
s3Client.PutBucket(putBucketRequest);
}
示例7: Push
public string Push(AmazonS3Client s3Client, AmazonCodeDeployClient codeDeployClient)
{
var zipFileName = string.Format("{0}.{1}.{2}.zip", ApplicationSetName, Version, BundleName);
var tempPath = Path.Combine(Path.GetTempPath(), zipFileName + "." + Guid.NewGuid() + ".zip");
ZipFile.CreateFromDirectory(_bundleDirectory.FullName, tempPath, CompressionLevel.Optimal, false, Encoding.ASCII);
var allTheBuckets = s3Client.ListBuckets(new ListBucketsRequest()).Buckets;
if (!allTheBuckets.Exists(b => b.BucketName == Bucket))
{
s3Client.PutBucket(new PutBucketRequest { BucketName = Bucket, UseClientRegion = true });
}
var putResponse = s3Client.PutObject(new PutObjectRequest
{
BucketName = Bucket,
Key = zipFileName,
FilePath = tempPath,
});
var registration = new RegisterApplicationRevisionRequest
{
ApplicationName = CodeDeployApplicationName,
Description = "Revision " + Version,
Revision = new RevisionLocation
{
RevisionType = RevisionLocationType.S3,
S3Location = new S3Location
{
Bucket = Bucket,
BundleType = BundleType.Zip,
Key = zipFileName,
Version = Version
}
}
};
try
{
codeDeployClient.RegisterApplicationRevision(registration);
}
catch (ApplicationDoesNotExistException)
{
codeDeployClient.CreateApplication(new CreateApplicationRequest { ApplicationName = CodeDeployApplicationName });
codeDeployClient.RegisterApplicationRevision(registration);
}
return putResponse.ETag;
}
示例8: NewDirectory
/// <summary>
/// create a new bucket in s3
/// </summary>
/// <param name="PathName"></param>
/// <returns></returns>
public bool NewDirectory(string PathName)
{
try
{
//amazon client
using (var client = new AmazonS3Client())
{
//put bucket request
using (var response = client.PutBucket(new PutBucketRequest()
.WithBucketName(PathName)))
{
return true;
}
}
}
catch (Exception ex)
{
Trace.WriteLine(ex.ToString());
}
return false;
}
示例9: PutBuck
private void PutBuck(AmazonS3Client client)
{
// Construct request
PutBucketRequest request = new PutBucketRequest
{
BucketName = "com.loofah.photos",
BucketRegion = S3Region.US, // set region to US
CannedACL = S3CannedACL.PublicRead // make bucket publicly readable
};
// Issue call
PutBucketResponse putBucketResponse = client.PutBucket(request);
}
示例10: 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;
}
}
示例11: BucketSamples
public void BucketSamples()
{
{
#region ListBuckets Sample
// Create a client
AmazonS3Client client = new AmazonS3Client();
// Issue call
ListBucketsResponse response = client.ListBuckets();
// View response data
Console.WriteLine("Buckets owner - {0}", response.Owner.DisplayName);
foreach (S3Bucket bucket in response.Buckets)
{
Console.WriteLine("Bucket {0}, Created on {1}", bucket.BucketName, bucket.CreationDate);
}
#endregion
}
{
#region BucketPolicy Sample
// Create a client
AmazonS3Client client = new AmazonS3Client();
// Put sample bucket policy (overwrite an existing policy)
string newPolicy = @"{
""Statement"":[{
""Sid"":""BasicPerms"",
""Effect"":""Allow"",
""Principal"": ""*"",
""Action"":[""s3:PutObject"",""s3:GetObject""],
""Resource"":[""arn:aws:s3:::samplebucketname/*""]
}]}";
PutBucketPolicyRequest putRequest = new PutBucketPolicyRequest
{
BucketName = "SampleBucket",
Policy = newPolicy
};
client.PutBucketPolicy(putRequest);
// Retrieve current policy
GetBucketPolicyRequest getRequest = new GetBucketPolicyRequest
{
BucketName = "SampleBucket"
};
string policy = client.GetBucketPolicy(getRequest).Policy;
Console.WriteLine(policy);
Debug.Assert(policy.Contains("BasicPerms"));
// Delete current policy
DeleteBucketPolicyRequest deleteRequest = new DeleteBucketPolicyRequest
{
BucketName = "SampleBucket"
};
client.DeleteBucketPolicy(deleteRequest);
// Retrieve current policy and verify that it is null
policy = client.GetBucketPolicy(getRequest).Policy;
Debug.Assert(policy == null);
#endregion
}
{
#region GetBucketLocation Sample
// Create a client
AmazonS3Client client = new AmazonS3Client();
// Construct request
GetBucketLocationRequest request = new GetBucketLocationRequest
{
BucketName = "SampleBucket"
};
// Issue call
GetBucketLocationResponse response = client.GetBucketLocation(request);
// View response data
Console.WriteLine("Bucket location - {0}", response.Location);
#endregion
}
{
#region PutBucket Sample
// Create a client
AmazonS3Client client = new AmazonS3Client();
// Construct request
PutBucketRequest request = new PutBucketRequest
{
//.........这里部分代码省略.........
示例12: Initialize
private static void Initialize()
{
NameValueCollection appConfig = ConfigurationManager.AppSettings;
_amazonS3Client = new AmazonS3Client(appConfig["AWSAccessKey"], appConfig["AWSSecretKey"]);
_folder = appConfig["SyncFolder"];
string password = appConfig["CryptoKey"];
Rfc2898DeriveBytes rfcDb = new Rfc2898DeriveBytes(password, System.Text.Encoding.UTF8.GetBytes(password));
Rijndael rijndael = Rijndael.Create();
byte[] key = rfcDb.GetBytes(32); //256 bits key
byte[] iv = rfcDb.GetBytes(16); // 128 bits key
_aesEncryptor = rijndael.CreateEncryptor(key, iv);
_aesDecryptor = rijndael.CreateDecryptor(key, iv);
ListBucketsResponse listBucketsResponse = _amazonS3Client.ListBuckets();
bool bucketIsExist = listBucketsResponse.Buckets.Any(s3Bucket => s3Bucket.BucketName == BucketName);
if (!bucketIsExist)
{
_amazonS3Client.PutBucket(new PutBucketRequest().WithBucketName(BucketName));
}
InitializeFileSystemWatcher();
}