An alternative implementation would be to use SaveAs on HttpPostedFile:
fileUpload.SaveAs(Path.Combine(uploadPath, fileName));
题
My code:
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);
}
}
I get an 'System.OutOfMemoryException' error.
My machine has 4 gigs of RAM. The file in question is approximately 1 GB. I am using plUpload to do the upload.
I've Enabled the 3GB switch. No difference. I have lots of RAM available, why am I running out of memory? Is there an alternative approach that uses less memory?
解决方案
An alternative implementation would be to use SaveAs on HttpPostedFile:
fileUpload.SaveAs(Path.Combine(uploadPath, fileName));