本文整理汇总了C#中AmazonS3类的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3类的具体用法?C# AmazonS3怎么用?C# AmazonS3使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AmazonS3类属于命名空间,在下文中一共展示了AmazonS3类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetInstance
private static void SetInstance()
{
if(theAmazonClient == null) {
theAmazonClient =
Amazon.AWSClientFactory.CreateAmazonS3Client(Configuration.SiteConfiguration.AWSAccessKey(), Configuration.SiteConfiguration.AWSSecretKey());
}
}
示例2: Main
public static void Main(string[] args)
{
if (checkRequiredFields())
{
using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(RegionEndpoint.USWest2))
{
Console.WriteLine("Listing buckets");
ListingBuckets();
Console.WriteLine("Creating a bucket");
CreateABucket();
Console.WriteLine("Writing an object");
WritingAnObject();
Console.WriteLine("Reading an object");
ReadingAnObject();
Console.WriteLine("Deleting an object");
DeletingAnObject();
Console.WriteLine("Listing objects");
ListingObjects();
}
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
示例3: PhysicallyDeletePhoto
public static S3Response PhysicallyDeletePhoto(AmazonS3 anS3Client, string aBucketName, string aFileName)
{
DeleteObjectRequest myDeleteRequest = new DeleteObjectRequest();
myDeleteRequest.WithBucketName(aBucketName).WithKey(aFileName);
return anS3Client.DeleteObject(myDeleteRequest);
}
示例4: S3FileSystem
//For testing - allows mocking of files and s3
public S3FileSystem(AmazonS3 s3Client, Func<string, IFileStreamWrap> fileLoader)
{
Logger = new TraceLogger();
S3Client = s3Client;
TransferUtility = new TransferUtility(s3Client);
FileLoader = fileLoader;
}
示例5: S3StorageProvider
public S3StorageProvider(AmazonS3 s3, string bucket, string rootKey = null)
{
_s3 = s3;
_bucket = bucket;
_rootKey = SanitizeKey(rootKey ?? "");
MaxParallelStreams = 4;
}
示例6: Main
public static void Main(string[] args)
{
_threadPool = new Semaphore(MaxThreads, MaxThreads);
using (_s3Client = AWSClientFactory.CreateAmazonS3Client(ConfigurationManager.AppSettings["AWSAccessKey"], ConfigurationManager.AppSettings["AWSSecretKey"]))
{
for (int level = StartLevel; level <= EndLevel; ++level)
{
double tileSize = WebMercatorDelta * Math.Pow(2, 1 - level);
int startRow = Convert.ToInt32(Math.Truncate((WebMercatorDelta - ExtentMaxY) / tileSize)) - TilePaddingY;
int endRow = Convert.ToInt32(Math.Truncate((WebMercatorDelta - ExtentMinY) / tileSize)) + 1 + TilePaddingY;
int startColumn = Convert.ToInt32(Math.Truncate((ExtentMinX + WebMercatorDelta) / tileSize)) - TilePaddingX;
int endColumn = Convert.ToInt32(Math.Truncate((ExtentMaxX + WebMercatorDelta) / tileSize)) + 1 + TilePaddingX;
for (int r = startRow; r <= endRow; ++r)
{
for (int c = startColumn; c <= endColumn; ++c)
{
_threadPool.WaitOne();
Thread t = new Thread(new ParameterizedThreadStart(CopyImage));
t.Start(new UserData(level, r, c));
Console.Write(String.Format("{0}Level {1} Row {2} Column {3}", new String('\b', 40), level, r, c).PadRight(80));
}
}
}
}
Console.WriteLine((new String('\b', 40) + "Done").PadRight(80));
Console.Read();
}
示例7: MessageGearsAwsClient
/// <summary>
/// Used to create a new instance of the MessageGears client.
/// </summary>
/// <param name="props">
/// Contains the credentials needed to access MessageGears, Amazon S3, and Amazon SQS.<see cref="MessageGearsProperties"/>
/// </param>
public MessageGearsAwsClient(MessageGearsAwsProperties props)
{
this.properties = props;
this.sqs = new AmazonSQSClient(properties.MyAWSAccountKey, properties.MyAWSSecretKey);
this.s3 = new AmazonS3Client(properties.MyAWSAccountKey, properties.MyAWSSecretKey);
log.Info("MessageGears AWS client initialized");
}
示例8: MultipartUploadCommand
/// <summary>
/// Initializes a new instance of the <see cref="MultipartUploadCommand"/> class.
/// </summary>
/// <param name="s3Client">The s3 client.</param>
/// <param name="config">The config object that has the number of threads to use.</param>
/// <param name="fileTransporterRequest">The file transporter request.</param>
internal MultipartUploadCommand(AmazonS3 s3Client, TransferUtilityConfig config, TransferUtilityUploadRequest fileTransporterRequest)
{
this._config = config;
if (fileTransporterRequest.IsSetFilePath())
{
this._logger.DebugFormat("Beginning upload of file {0}.", fileTransporterRequest.FilePath);
}
else
{
this._logger.DebugFormat("Beginning upload of stream.");
}
this._s3Client = s3Client;
this._fileTransporterRequest = fileTransporterRequest;
this._contentLength = this._fileTransporterRequest.ContentLength;
if (fileTransporterRequest.IsSetPartSize())
this._partSize = fileTransporterRequest.PartSize;
else
this._partSize = calculatePartSize(this._contentLength);
this._logger.DebugFormat("Upload part size {0}.", this._partSize);
}
示例9: ResizeImageAndUpload
public static void ResizeImageAndUpload(AmazonS3 anAmazonS3Client, string aBucketName, string aCurrentPhotoName, string aNewImageName, int aSize)
{
GetObjectRequest myGetRequest = new GetObjectRequest().WithBucketName(aBucketName).WithKey(aCurrentPhotoName);
GetObjectResponse myResponse = anAmazonS3Client.GetObject(myGetRequest);
Stream myStream = myResponse.ResponseStream;
ResizeAndUpload(myStream, anAmazonS3Client, aBucketName, aNewImageName, aSize);
}
示例10: S3Storage
/// <summary>
/// A Wrapper for the AWS.net SDK
/// </summary>
public S3Storage()
{
var accessKeyId = _dbContext.Key.SingleOrDefault(k => k.Name == "AccessKeyId").Data;
var secretAccessKey = _dbContext.Key.SingleOrDefault(k => k.Name == "SecretAccessKey").Data;
_client = AWSClientFactory.CreateAmazonS3Client(accessKeyId, secretAccessKey, RegionEndpoint.USEast1);
}
示例11: Main
public static void Main(string[] args)
{
NameValueCollection appConfig = ConfigurationManager.AppSettings;
accessKeyID = appConfig["AWSAccessKey"];
secretAccessKeyID = appConfig["AWSSecretKey"];
using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKeyID, secretAccessKeyID))
{
Console.WriteLine("Listing buckets");
ListingBuckets();
Console.WriteLine("Creating a bucket");
CreateABucket();
Console.WriteLine("Writing an object");
WritingAnObject();
Console.WriteLine("Reading an object");
ReadingAnObject();
Console.WriteLine("Deleting an object");
DeletingAnObject();
Console.WriteLine("Listing objects");
ListingObjects();
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
示例12: S3FetchClient
public S3FetchClient(IHttpRetryService httpRetryService,
IFileSystem fileSystem,
AmazonS3 s3)
{
this.httpRetryService = httpRetryService;
this.fileSystem = fileSystem;
this.s3 = s3;
}
示例13: DeleteFile
public static void DeleteFile(AmazonS3 Client, string filekey)
{
DeleteObjectRequest request = new DeleteObjectRequest()
{
BucketName = BUCKET_NAME,
Key = filekey
};
S3Response response = Client.DeleteObject(request);
}
示例14: Main
public static void Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
log.Info("Initializing and connecting to AWS...");
s3 = AWSClientFactory.CreateAmazonS3Client(RegionEndpoint.USWest1);
indexer = new FileIndexer("Files");
indexer.Index();
s3indexer = new S3Indexer(Settings.Default.BucketName, Settings.Default.FolderName, "S3Tmp", s3);
s3indexer.Index();
log.Info("Comparing local index and remote index.");
var filesToUpload = (from filePair in indexer.FileIndex where !s3indexer.HashedFiles.ContainsKey(filePair.Key) || !s3indexer.HashedFiles[filePair.Key].SequenceEqual(filePair.Value) select filePair.Key).ToList();
var filesToDelete = (from filePair in s3indexer.HashedFiles where !indexer.FileIndex.ContainsKey(filePair.Key) select filePair.Key).ToList();
foreach(var fileDelete in filesToDelete)
{
log.Debug("Deleting file "+fileDelete);
s3.DeleteObject(new DeleteObjectRequest()
{
BucketName = Settings.Default.BucketName,
Key = Settings.Default.FolderName + "/" + fileDelete
});
}
foreach(var fileUpload in filesToUpload)
{
log.Debug("Uploading file "+fileUpload);
s3.PutObject(new PutObjectRequest()
{
BucketName = Settings.Default.BucketName,
Key = Settings.Default.FolderName + "/" + fileUpload,
AutoCloseStream = true,
InputStream = new FileStream("Files/" + fileUpload, FileMode.Open)
});
}
log.Info("Re-indexing files...");
using (MemoryStream stream = new MemoryStream())
{
Serializer.Serialize(stream, indexer.FileIndex);
stream.Position = 0;
s3.PutObject(new PutObjectRequest()
{
BucketName = Settings.Default.BucketName,
Key = Settings.Default.FolderName + "/" + "index.mhash",
InputStream = stream
});
}
log.Info("Done!");
Console.Read();
}
示例15: S3
/// <summary>
/// Initializes a new instance of the S3
/// </summary>
/// <param name="client">Client</param>
/// <param name="bucket">Bucket</param>
/// <param name="relativePath">Relative Path</param>
/// <param name="etag">ETag</param>
public S3(AmazonS3 client, string bucket, string relativePath, string etag = null)
{
this.client = client;
this.bucket = bucket;
this.RelativePath = relativePath.Replace('\\', '/');
if (!string.IsNullOrWhiteSpace(etag))
{
this.MD5 = System.Convert.ToBase64String(StringToByteArray(etag.Replace("\"", string.Empty)));
}
}