【发布时间】:2019-02-20 18:23:25
【问题描述】:
我正在尝试将一个大型视频文件 (800mb) 上传到我的 S3 存储桶,但它似乎超时。它适用于较小的文件。我的项目是一个 ASP.Net Core 2.1 应用程序。
这是抛出的异常:
处理请求时发生未处理的异常。 SocketException:由于线程退出或应用程序请求,I/O 操作已中止。 位置不明
IOException:无法从传输连接中读取数据:I/O 操作已因线程退出或应用程序请求而中止。 System.Net.Sockets.Socket+AwaitableSocketAsyncEventArgs.ThrowException(SocketError 错误)
TaskCanceledException:操作已取消。 AWSS3Helper.cs 中的 GamerPilot.Video.AWSS3Helper.UploadFileAsync(流流,字符串键,S3CannedACL acl,bool useReducedRedundancy,bool throwOnError,CancellationToken cancelToken),第 770 行
我的源代码如下所示:
public async Task<IVideo> AddVideoAsync(int instructorId, int lectureId, string videoName, string filePath, CancellationToken cancellationToken = default(CancellationToken))
{
if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException("filePath", "Video filepath is missing"); }
if (!File.Exists(filePath)) { throw new ArgumentNullException("filePath", "Video filepath does not exists"); }
//Test video file upload and db row insertion
using (var stream = File.OpenRead(filePath))
{
return await AddVideoAsync(instructorId, lectureId, videoName, stream, cancellationToken);
}
}
public async Task<IVideo> AddVideoAsync(int instructorId, int lectureId, string videoName, Stream videoFile, CancellationToken cancellationToken = default(CancellationToken))
{
var video = (Video) await GamerPilot.Video.Helper.Create(_awsS3AccessKey, _awsS3SecretKey, _awsS3BucketName, _awsS3Region)
.AddVideoAsync(instructorId, lectureId, videoName, videoFile, cancellationToken);
using (var db = new DbContext(_connectionString))
{
db.Videos.Add(video);
var count = await db.SaveChangesAsync();
}
return video;
}`
public async Task<IVideo> AddVideoAsync(int instructorId, int lectureId, string videoName, Stream videoFile, CancellationToken cancellationToken = default(CancellationToken))
{
if (string.IsNullOrEmpty(videoName)) { throw new ArgumentNullException("videoName", "Video name cannot be empty or null"); }
if (videoFile == null) { throw new ArgumentNullException("video", "Video stream is missing"); }
var videoNameCleaned = videoName.Replace(" ", "-").ToLower().Replace(".mp4", "");
var videoKey = string.Join('/', "videos", instructorId, lectureId, videoNameCleaned + ".mp4");
using (var aws = new AWSS3Helper(_awsS3AccessKey, _awsS3SecretKey, _awsS3BucketName, _awsS3Region))
{
try
{
//THIS FAILS ------
await aws.UploadFileAsync(videoFile, videoKey, Amazon.S3.S3CannedACL.PublicRead, true, true, cancellationToken);
}
catch (Exception ex)
{
throw;
}
}
return new Video
{
InstructorId = instructorId,
LectureId = lectureId,
Name = videoName,
S3Key = videoKey,
S3Region = _awsS3Region.SystemName,
S3Bucket = _awsS3BucketName,
Created = DateTime.Now
};
}
我该如何解决这个问题?
【问题讨论】:
标签: amazon-web-services amazon-s3 asp.net-core task