【发布时间】:2013-07-06 02:22:27
【问题描述】:
我的代码:
int chunk = Request["chunk"] != null ? int.Parse(Request["chunk"]) : 0;
string fileName = Request["name"] != null ? Request["name"] : string.Empty;
Response.Write(Request.Files.Count);
HttpPostedFile fileUpload = Request.Files[0];
var uploadPath = Server.MapPath("~/uploaded-files");
if (Request.QueryString["originals"] == "yes")
{
using (var fs = new FileStream(Path.Combine(uploadPath, fileName), chunk == 0 ? FileMode.Create : FileMode.Append))
{
var buffer = new byte[fileUpload.InputStream.Length];
fileUpload.InputStream.Read(buffer, 0, buffer.Length);
fs.Write(buffer, 0, buffer.Length);
}
}
我收到“System.OutOfMemoryException”错误。
我的机器有 4 GB 的 RAM。有问题的文件大约为 1 GB。我正在使用 plUpload 进行上传。
我已启用 3GB 开关。没有不同。我有很多可用的 RAM,为什么我的内存不足?有没有使用更少内存的替代方法?
【问题讨论】:
-
分块读取和写入,而不是一次全部写入?
-
尝试为 x64 平台目标编译。
-
您是否在配置中弄乱了 httpRuntime 设置? HttpPostedFile 应该在超过 256KB 时缓冲到磁盘,除非您提高了 requestLengthDiskThreshold。
-
-
我要研究块上传
标签: c# asp.net file-upload plupload