我正在尝试在天蓝色中上传文件。
所以基本上我正在尝试将文件转换为流,以便我可以在服务器上创建一个文件并写入其数据。
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。我经常收到这个错误。似乎无法理解为什么。
我想只在创建的文件上写入。请帮忙:)
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)