我的代码:
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,为什么我的内存不足?是否有使用更少内存的替代方法?
最佳答案
另一种实现方式是使用 SaveAs在 HttpPostedFile 上:
fileUpload.SaveAs(Path.Combine(uploadPath, fileName));
关于c# - 上传文件时OutOfMemory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17494564/