【发布时间】:2019-07-10 20:27:13
【问题描述】:
我有一个 MVC GET 操作,它返回一个带有 byte[] 属性的 json 类模型,我用它来返回一条消息和文件,但是如果文件太大,我会得到一个 OutOfMemoryException,有没有返回不使用此类内存的文件和数据的其他方式?
我知道我可以创建另一个操作以仅返回最终文件,但我可以根据同一个请求执行此操作吗?
编辑:
我不想使用 byte[] 或任何将文件加载到内存中的方法
public ActionResult GetFile()
{
// Here: currently logic to create the final file and the message
// Here: I want to add the final file to the result
// Here: I want to add my model data(json) to the result
// Here: currently returning json with a byte[] property to return the file
return Json(myModel, JsonRequestBehavior.AllowGet);
}
【问题讨论】:
-
(rion.io/2013/04/28/…) 或考虑将您的文件压缩成 .zip
-
已经压缩了
-
也许你需要增加最大json长度属性
-
问题是,我不想使用缓冲,例如使用 byte[] 或字符串,唯一的方法是使用流,但我不知道如何使用它
-
所以你不想使用字节数组?还是你呢?因为您的帖子听起来像是您想使用字节数组
标签: c# asp.net-mvc