这是我创建图片网址的代码:
List<FileName> lstFileURL = AmazonFunction.GetFileUrlList(BucketName, BucketFolderName, Time);
创建 amazons3client 对象:
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";
}
}
}
我收到 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);
我正在使用 MVC 4。