c# - 无法访问已处置的对象。对象名称:FileBufferingReadStream
问题描述
我正在尝试以天蓝色上传文件。
所以基本上我试图将文件转换成流,这样我就可以在服务器上创建一个文件并写入它的数据。
public async Task UploadFileOnAzure( string path, string name, IFormFile file)
{
//create directory
await _dlsService.CreateDir(path, name);
//create file
var f = file.FileName;
var ext = Path.GetExtension(f);
string filepath = $"{path}/{name.ToString()}/{f}";
try
{
using (var ms = new MemoryStream())
{
using (var fileStram = file.OpenReadStream())
{//sometimes it breakes right before this line, other times it doesn't write the file(excel)
fileStram.CopyTo(ms);
using (Stream str = await _dlsService.CreateFile(filepath)) //file is created as empty ofcourse
{
ms.CopyTo(str);
str.Close();
//this doesnt write on the file
}
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
}
无法访问已处置的对象。对象名称:FileBufferingReadStream。我经常收到这个错误。似乎无法理解为什么。我只想写在创建的文件上。请帮助:)
解决方案
推荐阅读
- python - 无法更新 mongoDB 文档
- android - 如果项目存在于数据库中,为什么 Room 查询返回 null?
- javascript - 使用复选框以 Acrobat DC 形式计算
- swift - 立即关闭声音
- wordpress - 子目录安装中的Wordpress 403禁止错误
- python - Project Euler 问题 8 Python 整数溢出
- html - “bootstrap min css 1 加载资源失败:net::err_file_not_found”
- python - 为什么django模型保存功能没有响应?
- java - 使用spring boot和crud如何同时更新两个类的列表(它们之间存在关系)
- r - %in% 没有给出正确的输出