从 Amazon s3 读取图像和视频时,在 System.Net.HttpWebRequest.GetResponse
本文关键字:System Net GetResponse HttpWebRequest 视频 s3 Amazon 读取 图像 | 更新日期: 2023-09-27 18:34:47
这是我创建图像网址的代码:
List<FileName> lstFileURL = AmazonFunction.GetFileUrlList(BucketName, BucketFolderName, Time);
创建 Amazonons3Client 对象:
private static AmazonS3Client GetS3Client()
{
NameValueCollection appConfig = ConfigurationManager.AppSettings;
AmazonS3Client s3Client = (AmazonS3Client)AWSClientFactory.CreateAmazonS3Client(
appConfig["AWSAccessKey"],
appConfig["AWSSecretKey"],
RegionEndpoint.USEast1
);
return s3Client;
}
创建图片网址列表:
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;
}
这是我创建视频网址的代码:
VideoFilePath = AmazonFunction.GetFileURL(BucketName, videotitle, Time);
创建视频网址 :
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";
}
}
}
我正在收到系统.Net.Web异常:操作在以下行上超时:
List<FileName> lstFileURL = AmazonFunction.GetFileUrlList(BucketName, BucketFolderName, Time);
VideoFilePath = AmazonFunction.GetFileURL(BucketName, videotitle, Time);
我正在使用 MVC 4。
尝试在 web.config 中添加以下配置。
<system.net>
<defaultProxy enabled = "true" useDefaultCredentials = "true"/>
</system.net>