将内容复制到流中时HttpRequestException错误(Cloudinary上传)
我正在尝试建立一个项目,用户可以在其中上传小视频.我创建了以下类来处理有关如何上传视频的Cloudinary代码.对于非常短的视频(例如0.3秒的视频),它的效果很好,但是当我尝试上传超过0.10秒的视频时,我却遇到了例外情况:
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:将内容复制到流时出错.
System.Net.Http.HttpRequestException: Error while copying content to a stream.
视频正在上传到Cloudinary.这是代码:
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?
堆栈跟踪:
System.Threading.Tasks.TaskCanceledException:操作已取消.
System.Net.Http.HttpRequestException:将内容复制到流时出错.
System.IO.IOException:无法从传输连接读取数据:由于线程退出或应用程序请求,I/O操作已中止
System.Net.Sockets.SocketException(995):由于线程退出或应用程序请求,I/O操作已中止.
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.
您的上传请求可能已超时.您可能需要使用UploadLarge方法分批上传视频.参见-https://github.com/cloudinary/CloudinaryDotNet/blob/a3a4d38c4fd7c1b03beeb3eed7d8ea725866a36c/Shared/Cloudinary.cs#L1229
Your upload request was probably timing out. You should probably need to upload your videos in chunks using the UploadLarge method. See -https://github.com/cloudinary/CloudinaryDotNet/blob/a3a4d38c4fd7c1b03beeb3eed7d8ea725866a36c/Shared/Cloudinary.cs#L1229
有关更多信息: https://cloudinary.com/documentation/upload_images#chunked_asset_upload