AWS S3 GetObjectAsync挂起/超时 [英] AWS S3 GetObjectAsync Hangs/Times Out

查看:430
本文介绍了AWS S3 GetObjectAsync挂起/超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:回答我自己的问题,以后可以帮助其他人.

我正在遵循官方文档 S3存储桶中的一个文本文件挂起:

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"];

我如何使它工作?

推荐答案

此问题在此处我的问题是我从WinForm应用程序运行此示例.

The problem for me I was running this example from a WinForm app.

Winform应用程序Main()方法用单线程单元属性[STAThread]标记.这会导致异步操作失败.

Winform apps Main() methods are marked with Single Threaded Apartment attribute [STAThread]. This causes the Async's to fail.

要么删除[STAThread]属性,要么创建另一个没有它的Main()方法.

Either remove the [STAThread] attribute or make another Main() method without it.

这篇关于AWS S3 GetObjectAsync挂起/超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆