我正在尝试使用 将大图像文件上传到 cloudinary IFormFile
,但出现以下错误:
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.
--- End of inner exception stack trace ---
该代码使用文件流上传图像:
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("60").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
};
}
videouploadresult
只是一个简单的类,它在上传到 Cloudinary 时具有文件的和publicid
属性url
。有没有其他方法可以通过 API 上传大文件?还是代码有问题?
它适用于 30MB 以下的文件,我还允许我的 kestrel sevrer 能够上传高达 200MB 的文件,但我仍然遇到错误。我认为该错误源于尝试打开大文件的读取流,并且我已经阅读过使用IFormFile
大文件不好的地方。但我还没有看到任何替代方案。