简体   繁体   English

从亚马逊 s3 读取图像和视频时,在 System.Net.HttpWebRequest.GetResponse() 处获取 WebException“操作已超时”

[英]Getting WebException “The operation has timed out” at System.Net.HttpWebRequest.GetResponse() when reading images and video from amazon s3

Here is my code to create image url :这是我创建图像 url 的代码:

List<FileName> lstFileURL = AmazonFunction.GetFileUrlList(BucketName, BucketFolderName, Time);

create amazons3client object :创建 amazons3client 对象:

private static AmazonS3Client GetS3Client()
            {
                NameValueCollection appConfig = ConfigurationManager.AppSettings;

                AmazonS3Client s3Client = (AmazonS3Client)AWSClientFactory.CreateAmazonS3Client(
                        appConfig["AWSAccessKey"],
                        appConfig["AWSSecretKey"],
                        RegionEndpoint.USEast1
                        );
                return s3Client;
            }

create image url list :创建图片网址列表:

    public static List<FileName> GetFileUrlList(string BUCKET_NAME, string name, double Time)
                {

                    List<FileName> ListImageName = new List<FileName>();
                    using (GetS3Client())
                    {
                        try
                        {
                            ListObjectsRequest Lor = new ListObjectsRequest()
                            {
                                BucketName = BUCKET_NAME,
                                // with Prefix is a folder Key, it will list only child of that folder
                                Prefix = name,
                                //with Delimiter is '/', it will not get folder.
                                Delimiter = "/"
                            };
                            ListObjectsResponse response1 = GetS3Client().ListObjects(Lor);



                            //ListBuckets

                            for (int i = 0; i < response1.S3Objects.Count; i++)
                            {
                                ListImageName.Add(new FileName(MakeUrl(BUCKET_NAME, response1.S3Objects[i].Key.ToString().Split('/')response1.S3Objects[i].Key.ToString().Split('/').Length - 1], Time)));

                            }


                        }
                        catch (AmazonS3Exception ex)
                        {
                            //Show Exception
                        }
                    }
                    return ListImageName;
                }

Here is my code to create video url :这是我创建视频网址的代码:

VideoFilePath = AmazonFunction.GetFileURL(BucketName, videotitle, Time);

create video url :创建视频网址:

        public static string GetFileURL(string BUCKET_NAME, string FILE_NAME, double TIME)
                {
                    using (GetS3Client())
                    {
                        try
                        {
                            GetObjectRequest gor = new GetObjectRequest()
                            {
                                BucketName = BUCKET_NAME,
                                Key = FILE_NAME,
                            };

                            GetObjectResponse response = GetS3Client().GetObject(gor);

                            string FileURL = MakeUrl(BUCKET_NAME, FILE_NAME, TIME);

                            return FileURL;
                        }
                        catch (AmazonS3Exception ex)
                        {
                            return "FileNotFound";
                        }
                    }
                }

I am getting System.Net.WebException: The operation has timed out on below lines :我收到 System.Net.WebException: The operation has timed out on 以下几行:

List<FileName> lstFileURL = AmazonFunction.GetFileUrlList(BucketName, BucketFolderName, Time);
VideoFilePath = AmazonFunction.GetFileURL(BucketName, videotitle, Time);

I am using MVC 4.我正在使用 MVC 4。

Try adding the below config in your web.config.尝试在您的 web.config 中添加以下配置。

    <system.net>
            <defaultProxy enabled = "true" useDefaultCredentials = "true"/>
    </system.net>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Net.WebException:操作在 System.Net.HttpWebRequest.GetResponse 超时 - System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse 向主机发送大量请求时 System.Net.HttpWebRequest.GetResponse() 的操作超时 - The operation has timed out at System.Net.HttpWebRequest.GetResponse() while sending large number of requests to a host HttpWebRequest .GetResponse 抛出 WebException &#39;操作已超时&#39; - HttpWebRequest .GetResponse throws WebException 'The operation has timed out' 我正在获取WebException:“操作已超时”立即在HttpWebRequest.GetResponse()上 - I am getting WebException: “The operation has timed out” immediately on HttpWebRequest.GetResponse() System.Net.WebException:远程服务器返回错误:(401)未经授权。 在System.Net.HttpWebRequest.GetResponse() - System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() HttpWebRequest.GetResponse操作已超时 - HttpWebRequest.GetResponse Operation has timed out System.Net.HttpWebRequest.GetResponse()中的错误“ResponceSystem.Net.WebException:请求已中止:无法创建SSL / TLS安全通道” - Error in System.Net.HttpWebRequest.GetResponse() “ResponceSystem.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel” System.Net.WebException:操作已在HttpWebResponse上超时 - System.Net.WebException: The operation has timed out on HttpWebResponse System.Net.WebException:操作已超时 - System.Net.WebException: The operation has timed out HttpWebRequest 上传文件原因 操作超时 WebException - HttpWebRequest upload file cause The operation has timed out WebException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM