AWS S3 GetObjectAsync Hangs/Times Out

与世无争的帅哥 提交于 2020-01-04 07:02:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!