问题
Note: Answering my own question to help others in the future.
I'm following the official documentation to get a text file from an S3 bucket and it hangs:
static async Task ReadObjectDataAsync()
{
string responseBody = "";
try
{
GetObjectRequest request = new GetObjectRequest
{
BucketName = bucketName,
Key = keyName
};
//THIS NEXT LINE HANGS!!!!
using (GetObjectResponse response = await client.GetObjectAsync(request))
using (Stream responseStream = response.ResponseStream)
using (StreamReader reader = new StreamReader(responseStream))
{
string title = response.Metadata["x-amz-meta-title"];
How do I get this to work?
回答1:
This issue has solutions here https://github.com/aws/aws-sdk-net/issues/152
The problem for me I was running this example from a WinForm app.
Winform apps Main()
methods are marked with Single Threaded Apartment attribute [STAThread]
. This causes the Async's to fail.
Either remove the [STAThread]
attribute or make another Main()
method without it.
来源:https://stackoverflow.com/questions/50920575/aws-s3-getobjectasync-hangs-times-out