本文整理汇总了C#中IAmazonS3类的典型用法代码示例。如果您正苦于以下问题:C# IAmazonS3类的具体用法?C# IAmazonS3怎么用?C# IAmazonS3使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IAmazonS3类属于命名空间,在下文中一共展示了IAmazonS3类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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(IAmazonS3 s3Client, TransferUtilityConfig config, TransferUtilityUploadRequest fileTransporterRequest)
{
this._config = config;
if (fileTransporterRequest.IsSetFilePath())
{
_logger.DebugFormat("Beginning upload of file {0}.", fileTransporterRequest.FilePath);
}
else
{
_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);
if (fileTransporterRequest.InputStream != null)
{
if (fileTransporterRequest.AutoResetStreamPosition && fileTransporterRequest.InputStream.CanSeek)
{
fileTransporterRequest.InputStream.Seek(0, SeekOrigin.Begin);
}
}
_logger.DebugFormat("Upload part size {0}.", this._partSize);
}
示例2: GetHeadAsync
internal static async Task<GetHeadResponse> GetHeadAsync(IAmazonS3 s3Client, IClientConfig config, string url, string header)
{
if (s3Client != null)
{
using (var httpClient = GetHttpClient(config))
{
var request = new HttpRequestMessage(HttpMethod.Head, url);
var response = await httpClient.SendAsync(request).ConfigureAwait(false);
foreach (var headerPair in response.Headers)
{
if (string.Equals(headerPair.Key, HeaderKeys.XAmzBucketRegion, StringComparison.OrdinalIgnoreCase))
{
foreach (var value in headerPair.Value)
{
// If there's more than one there's something really wrong.
// So just use the first one anyway.
return new GetHeadResponse
{
HeaderValue = value,
StatusCode = response.StatusCode
};
}
}
}
}
}
return null;
}
示例3: S3VirtualPathProvider
public S3VirtualPathProvider(IAmazonS3 client, string bucketName, IAppHost appHost)
: base(appHost)
{
this.AmazonS3 = client;
this.BucketName = bucketName;
this.rootDirectory = new S3VirtualDirectory(this, null);
}
示例4: SimpleUploadCommand
internal SimpleUploadCommand(IAmazonS3 s3Client, TransferUtilityConfig config, TransferUtilityUploadRequest fileTransporterRequest)
{
this._s3Client = s3Client;
this._config = config;
this._fileTransporterRequest = fileTransporterRequest;
var fileName = fileTransporterRequest.FilePath;
}
示例5: ToTransportMessage
public static TransportMessage ToTransportMessage(this SqsTransportMessage sqsTransportMessage, IAmazonS3 amazonS3, SqsConnectionConfiguration connectionConfiguration)
{
var messageId = sqsTransportMessage.Headers[Headers.MessageId];
var result = new TransportMessage(messageId, sqsTransportMessage.Headers);
if (!string.IsNullOrEmpty(sqsTransportMessage.S3BodyKey))
{
var s3GetResponse = amazonS3.GetObject(connectionConfiguration.S3BucketForLargeMessages, sqsTransportMessage.S3BodyKey);
result.Body = new byte[s3GetResponse.ResponseStream.Length];
using (BufferedStream bufferedStream = new BufferedStream(s3GetResponse.ResponseStream))
{
int count;
int transferred = 0;
while ((count = bufferedStream.Read(result.Body, transferred, 8192)) > 0)
{
transferred += count;
}
}
}
else
{
result.Body = Convert.FromBase64String(sqsTransportMessage.Body);
}
result.TimeToBeReceived = sqsTransportMessage.TimeToBeReceived;
if (sqsTransportMessage.ReplyToAddress != null)
{
result.Headers[Headers.ReplyToAddress] = sqsTransportMessage.ReplyToAddress.ToString();
}
return result;
}
示例6: ToTransportMessage
public static TransportMessage ToTransportMessage(this SqsTransportMessage sqsTransportMessage, IAmazonS3 amazonS3, SqsConnectionConfiguration connectionConfiguration)
{
var messageId = sqsTransportMessage.Headers[Headers.MessageId];
var result = new TransportMessage(messageId, sqsTransportMessage.Headers);
if (!string.IsNullOrEmpty(sqsTransportMessage.S3BodyKey))
{
var s3GetResponse = amazonS3.GetObject(connectionConfiguration.S3BucketForLargeMessages, sqsTransportMessage.S3BodyKey);
result.Body = new byte[s3GetResponse.ResponseStream.Length];
s3GetResponse.ResponseStream.Read(result.Body, 0, result.Body.Length);
}
else
{
result.Body = Convert.FromBase64String(sqsTransportMessage.Body);
}
result.TimeToBeReceived = sqsTransportMessage.TimeToBeReceived;
if (sqsTransportMessage.ReplyToAddress != null)
{
result.Headers[Headers.ReplyToAddress] = sqsTransportMessage.ReplyToAddress.ToString();
}
return result;
}
示例7: S3PutBase
protected S3PutBase(IAmazonS3 amazonS3)
{
if (null == amazonS3)
throw new ArgumentNullException(nameof(amazonS3));
AmazonS3 = amazonS3;
}
示例8: AbortMultipartUploadsCommand
internal AbortMultipartUploadsCommand(IAmazonS3 s3Client, string bucketName, DateTime initiateDate, TransferUtilityConfig config)
{
this._s3Client = s3Client;
this._bucketName = bucketName;
this._initiatedDate = initiateDate;
this._config = config;
}
示例9: AwsManager
public AwsManager(IAmazonS3 amazonS3, IPathManager pathManager)
{
if (null == amazonS3)
throw new ArgumentNullException(nameof(amazonS3));
if (null == pathManager)
throw new ArgumentNullException(nameof(pathManager));
_pathManager = pathManager;
_amazonS3 = amazonS3;
var storageClass = S3StorageClass.Standard;
var storageClassString = ConfigurationManager.AppSettings["AwsStorageClass"];
if (!string.IsNullOrWhiteSpace(storageClassString))
storageClass = S3StorageClass.FindValue(storageClassString);
var blobStorageClass = storageClass;
var blobStorageClassString = ConfigurationManager.AppSettings["AwsBlobStorageClass"];
if (!string.IsNullOrWhiteSpace(blobStorageClassString))
blobStorageClass = S3StorageClass.FindValue(blobStorageClassString);
var linkStorageClass = storageClass;
var linkStorageClassString = ConfigurationManager.AppSettings["AwsLinkStorageClass"];
if (!string.IsNullOrWhiteSpace(linkStorageClassString))
linkStorageClass = S3StorageClass.FindValue(linkStorageClassString);
_s3Blobs = new S3Blobs(amazonS3, pathManager, blobStorageClass);
_s3Links = new S3Links(amazonS3, pathManager, linkStorageClass);
}
示例10: 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(IAmazonS3 s3Client, TransferUtilityConfig config, TransferUtilityUploadRequest fileTransporterRequest)
{
this._config = config;
if (fileTransporterRequest.IsSetFilePath())
{
_logger.DebugFormat("Beginning upload of file {0}.", fileTransporterRequest.FilePath);
}
else
{
_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);
_logger.DebugFormat("Upload part size {0}.", this._partSize);
}
示例11: CacheAlbum
private async Task<Album> CacheAlbum(HttpClient httpClient, IAmazonS3 s3Client, JsonAlbum jsonAlbum, IList<string> cachedObjects, CancellationToken ctx)
{
var image = jsonAlbum.Image.Where(i => i.Size == JsonAlbumImageSize.Medium && i.Url != null).SingleOrDefault();
if (image == null)
{
return null;
}
var album = new Album
{
Artist = jsonAlbum.Artist,
Name = jsonAlbum.Name,
Playcount = jsonAlbum.Playcount,
Rank = jsonAlbum.Attributes.Rank,
Url = jsonAlbum.Url
};
var objectKey = album.ToString().ToSlug();
album.Thumbnail = new Uri($"https://s3-eu-west-1.amazonaws.com/{BucketName}/{objectKey}");
// If the album art was cached already, return
if (cachedObjects.Any(k => k == objectKey))
{
return album;
}
string mediaType;
byte[] imageBytes;
try
{
logger.LogInformation($"Downloading art for {album}");
var response = await httpClient.GetAsync(image.Url, ctx);
mediaType = response.Content.Headers?.ContentType?.MediaType;
imageBytes = await response.Content.ReadAsByteArrayAsync();
}
catch (Exception ex)
{
// If anything happened here, log and continue. We don't want to retry.
logger.LogWarning($"Hit exception whilst trying to download art for {album}", ex);
return null;
}
PutObjectResponse putResponse;
using (var ms = new MemoryStream(imageBytes))
{
logger.LogVerbose($"Storing art for {album}");
putResponse = await s3Client.PutObjectAsync(new PutObjectRequest
{
BucketName = BucketName,
ContentType = mediaType,
InputStream = ms,
Key = objectKey,
StorageClass = S3StorageClass.ReducedRedundancy,
CannedACL = S3CannedACL.PublicRead
}, ctx);
}
return album;
}
示例12: CodeDeployProcessor
public CodeDeployProcessor(IApplicationEnvironment appEnv, IConfiguration configuration, UtilityService utilties,
IAmazonS3 s3Client, IAmazonCodeDeploy codeDeployClient)
{
this.AppEnv = appEnv;
this.Configuration = configuration;
this.Utilities = utilties;
this.S3Client = s3Client;
this.CodeDeployClient = codeDeployClient;
}
示例13: AmazonS3StorageProvider
public AmazonS3StorageProvider(IAmazonS3StorageConfiguration amazonS3StorageConfiguration)
{
_amazonS3StorageConfiguration = amazonS3StorageConfiguration;
var cred = new BasicAWSCredentials(_amazonS3StorageConfiguration.AWSAccessKey, _amazonS3StorageConfiguration.AWSSecretKey);
//TODO: aws region to config
_client = new AmazonS3Client(cred, RegionEndpoint.USEast1);
var config = new TransferUtilityConfig();
_transferUtility = new TransferUtility(_client, config);
}
示例14: ScreenshotUploader
public ScreenshotUploader(Secrets secrets, string userToken, IMessageBus messageBus)
{
this._bucket = secrets.Name;
this._token = userToken;
this._client = new AmazonS3Client(secrets.Key, secrets.Secret, RegionEndpoint.USEast1);
this._messageBus = messageBus;
}
示例15: AlbumCacheTask
public AlbumCacheTask(ILastfmClientFactory lastfmFactory, IS3ClientFactory s3Factory, ICacheProvider cacheProvider, ILogger<AlbumCacheTask> logger)
{
this.s3Client = s3Factory.CreateS3Client();
this.lastfmClient = lastfmFactory.CreateLastfmClient();
this.cacheProvider = cacheProvider;
this.logger = logger;
}