我正在尝试从Asp.NET mvc应用程序中将文件保存在一个驱动器中。我成功登录但是当我尝试使用此方法放置流文件时:
var uploadedItem = await service.Drive.Root.ItemWithPath(uploadPath)
.Content.Request().PutAsync<Item>(str);
文件上传但是当我下载它时,它是空的,0字节。我被卡住了!
欢迎所有帮助,谢谢!
更新
问题是我从HttpPostedFileBase
文件获取流文件,它在上周工作正常。我没有在那里修改任何东西,本周问题就开始了。
我临时修复了将此文件保存到解决方案的本地文件夹中的问题:
private System.IO.Stream GetFileStreamForUpload(string tempFilePath)
{
try
{
return new System.IO.FileStream(tempFilePath, System.IO.FileMode.Open);
}
catch (Exception ex)
{
throw ex;
}
}
...
var fileStream = GetFileStreamForUpload(filePath);
var uploadedItem = await service.Drive.Root.ItemWithPath(uploadPath)
.Content.Request().PutAsync<Item>(fileStream);
但我真的不喜欢这个解决方案。