2

Here is my code to create image url :

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

create amazons3client object :

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 :

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

I am using MVC 4.

Shreekant
  • 111
  • 2
  • 11
  • How big are these assets? HTTP itself may be timing out, if you're trying to download the entire video in one call. You may want to download it in chunks. – JeffFerguson Dec 19 '14 at 14:40
  • I am trying to create URL of video to read from amazon s3 and playing in HTML 5 player. Not downloading the whole video. And list of image URLs to display in page. – Shreekant Dec 19 '14 at 16:44
  • This code is working fine on development machine but when I am hosting it in server it throws this exception. – Shreekant Dec 19 '14 at 16:49
  • What are the details (error codes, messages) in the exception object? – JeffFerguson Dec 19 '14 at 16:57
  • Actually i am writing error log in text file. so unable to find error code. below is the error msg and inner exception. Error Message : A WebException with status Timeout was thrown. Inner exception : System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse() at Amazon.Runtime.Internal.HttpRequest.GetResponse() source : AWSSDK – Shreekant Dec 22 '14 at 05:06

1 Answers1

0

Try adding the below config in your web.config.

    <system.net>
            <defaultProxy enabled = "true" useDefaultCredentials = "true"/>
    </system.net>
ankit
  • 111
  • 1
  • 5
  • could you add some explanation on how does in help? this will help understanding your answer to other developers as well. – Anand Vidvat May 12 '21 at 10:27