0
votes

I'm trying to upload a large video file (800mb) to my S3 bucket, but it appears to timeout. It works just fine for smaller files. My project is an ASP.Net Core 2.1 application.

This is the exception that is thrown:

An unhandled exception occurred while processing the request. SocketException: The I/O operation has been aborted because of either a thread exit or an application request. Unknown location

IOException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request. System.Net.Sockets.Socket+AwaitableSocketAsyncEventArgs.ThrowException(SocketError error)

TaskCanceledException: The operation was canceled. GamerPilot.Video.AWSS3Helper.UploadFileAsync(Stream stream, string key, S3CannedACL acl, bool useReducedRedundancy, bool throwOnError, CancellationToken cancellationToken) in AWSS3Helper.cs, line 770

My source code looks like this:

  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
        };
    }

How can I work around this?

1

1 Answers

0
votes

There is no general constraint on S3 itself which would prevent you from uploading an 800MB file. However, there are requirements for the handling of retries and timeouts when working with AWS. It is not clear from your question whether or not you are using Amazon's SDK, (I can't find the origin of GamerPilot.Video.AWSS3Helper.UploadFileAsync). However, Amazon's SDK for .NET should handle this for you if you use it in accordance with the following:

Programming with the AWS SDK for .NET - Retries and Timeouts

Using the AWS SDK for .NET for Multipart Upload (High-Level API)