c# - 如何将大图像文件上传到云资产管理服务(Cloudinary)?
问题描述
我正在尝试使用 将大图像文件上传到 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
大文件不好的地方。但我还没有看到任何替代方案。
解决方案
推荐阅读
- r - ggplot2 facet_grid:如何修复 geom_col 中列之间的不同间距
- python - 如何根据多个索引和多个条件过滤一行?
- spring - Сamunda 替换测试中外部任务的行为
- python - 不兼容和旧的 pip 包。许多操作在 Flow Project 中无法稳定运行
- visual-studio - 这是 Visual Studio 或 AxWMPLib::AxWindowsMediaPlayer 上的错误吗?
- python - 如何将 cupy 数据转换为 PyTorch 张量?
- android - OnOptionsItemSelected 未在 xamarin froms 中调用 - AndroidX
- amazon-web-services - 我为我的应用程序设置了一个 centos7 服务器,但无法将其连接到 aws
- python - 如何在椭圆内找到点?
- logging - 我在哪里可以关注 appBuilder 正在做什么?