I'm trying to build out a project where users can upload small videos. I've created the below class to handle my Cloudinary code on how to upload a video. It works fine for videos that are very short like 0.3 sec videos but when I try to upload more than 0.10 secs - I get an exception:
System.Net.Http.HttpRequestException: Error while copying content to a stream.
The videos are being uploaded to Cloudinary. Here's the code:
public class VideoAccessor : IVideoAccessor
{
private readonly Cloudinary _cloudinary;
public VideoAccessor(IConfiguration config)
{
// instantiate a new instance of cloudinary using details provided
_cloudinary = new Cloudinary(config["cloudinary"]);
}
public VideoUploadResult UploadClip(IFormFile videoFile)
{
var uploadResult = new CloudinaryDotNet.Actions.VideoUploadResult();
if (videoFile.Length > 0)
{
// create a new file stream to upload the video to cloudinary
using (var filestream = videoFile.OpenReadStream())
{
var uploadParams = new VideoUploadParams
{
File = new FileDescription(videoFile.FileName, filestream),
Transformation = new Transformation().StartOffset("0").EndOffset("120").Crop("fill")
};
uploadResult = _cloudinary.Upload(uploadParams);
}
}
// checks if error occurs when uploading video
if (uploadResult.Error != null)
{
throw new Exception(uploadResult.Error.Message);
}
return new VideoUploadResult
{
PublicId = uploadResult.PublicId,
Url = uploadResult.SecureUrl.AbsoluteUri
};
}
}
}
When trying to upload I get an exception. Does anyone know what I can add to this or how to make it more acceptable for larger files?
The stack trace:
System.Threading.Tasks.TaskCanceledException: The operation was canceled.
System.Net.Http.HttpRequestException: Error while copying content to a stream.
System.IO.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.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request.
TaskCanceledExceptionat the top of the stack. Does the library supportasynccalls? - stuartd