本文整理汇总了C#中IAmazonS3.GetObject方法的典型用法代码示例。如果您正苦于以下问题:C# IAmazonS3.GetObject方法的具体用法?C# IAmazonS3.GetObject怎么用?C# IAmazonS3.GetObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAmazonS3
的用法示例。
在下文中一共展示了IAmazonS3.GetObject方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: DownloadToByteArray
public override byte[] DownloadToByteArray(string container, string fileName)
{
client = AWSClientFactory.CreateAmazonS3Client(ExtendedProperties["accessKey"], ExtendedProperties["secretKey"], RegionEndpoint.USEast1);
String S3_KEY = fileName;
GetObjectRequest request = new GetObjectRequest()
{
BucketName = container,
Key = S3_KEY,
};
GetObjectResponse response = client.GetObject(request);
int numBytesToRead = (int)response.ContentLength;
int numBytesRead = 0;
byte[] buffer = new byte[numBytesToRead];
while (numBytesToRead > 0)
{
int n = response.ResponseStream.Read(buffer, numBytesRead, numBytesToRead);
if (n == 0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
return buffer;
}
示例4: ReadObjectData
static string ReadObjectData()
{
string responseBody = "";
using (client = new AmazonS3Client(Amazon.RegionEndpoint.EUWest1))
{
GetObjectRequest request = new GetObjectRequest
{
BucketName = bucketName,
Key = keyName
};
using (GetObjectResponse response = client.GetObject(request))
using (Stream responseStream = response.ResponseStream)
using (StreamReader reader = new StreamReader(responseStream))
{
string title = response.Key;
Console.WriteLine("The object's title is {0}", title);
responseBody = reader.ReadToEnd();
}
}
return responseBody;
}
示例5: PutObjectWithQuestionableKey
static void PutObjectWithQuestionableKey(IAmazonS3 s3Client, string bucketName, string keyName)
{
const string testContent = "Some stuff to write as content";
s3Client.PutObject(new PutObjectRequest
{
BucketName = bucketName,
Key = keyName,
ContentBody = testContent
});
var response = s3Client.GetObject(new GetObjectRequest
{
BucketName = bucketName,
Key = keyName
});
using (var s = new StreamReader(response.ResponseStream))
{
var responseContent = s.ReadToEnd();
Assert.AreEqual(testContent, responseContent);
}
}
示例6: PutObjectWithQuestionableKey
static void PutObjectWithQuestionableKey(IAmazonS3 s3Client, string bucketName, string keyName)
{
const string testContent = "Some stuff to write as content";
s3Client.PutObject(new PutObjectRequest
{
BucketName = bucketName,
Key = keyName,
ContentBody = testContent
});
var response = s3Client.GetObject(new GetObjectRequest
{
BucketName = bucketName,
Key = keyName
});
using (var s = new StreamReader(response.ResponseStream))
{
var responseContent = s.ReadToEnd();
Assert.AreEqual(testContent, responseContent);
}
var presignedUrl = s3Client.GetPreSignedURL(new GetPreSignedUrlRequest
{
BucketName = bucketName,
Key = keyName,
Verb = HttpVerb.GET,
Expires = DateTime.Now + TimeSpan.FromDays(5)
});
var httpRequest = HttpWebRequest.Create(presignedUrl);
using(var httpResponse = httpRequest.GetResponse())
using(var reader = new StreamReader(httpResponse.GetResponseStream()))
{
var content = reader.ReadToEnd();
Assert.AreEqual(testContent, content);
}
}
示例7: WaitForObject
public static void WaitForObject(IAmazonS3 client, string bucketName, string key, int maxSeconds)
{
var sleeper = new UtilityMethods.ListSleeper(500, 1000, 2000, 5000);
UtilityMethods.WaitUntilSuccess(() => { client.GetObject(bucketName, key); }, sleeper, 30);
}