Skip to content

Commit afd29ef

Browse files
committed
Removed buffer use
Sometimes it causes outOfMemoryException and there's no need to write to a separate buffer since you can copy the inputStream directly to the file.
1 parent 0e51c08 commit afd29ef

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

jQuery-File-Upload.MVC3/Upload/UploadHandler.ashx.cs

+2-11
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,7 @@ private void UploadPartialFile(string fileName, HttpContext context, List<FilesS
108108

109109
using (var fs = new FileStream(fullName, FileMode.Append, FileAccess.Write))
110110
{
111-
var buffer = new byte[1024];
112-
113-
var l = inputStream.Read(buffer, 0, 1024);
114-
while (l > 0)
115-
{
116-
fs.Write(buffer, 0, l);
117-
l = inputStream.Read(buffer, 0, 1024);
118-
}
119-
fs.Flush();
120-
fs.Close();
111+
inputStream.CopyTo(fs);
121112
}
122113
statuses.Add(new FilesStatus(new FileInfo(fullName)));
123114
}
@@ -194,4 +185,4 @@ private void ListCurrentFiles(HttpContext context)
194185
}
195186

196187
}
197-
}
188+
}

0 commit comments

Comments
 (0)