Skip to content

Instantly share code, notes, and snippets.

@maxim75
Created June 28, 2011 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxim75/1050481 to your computer and use it in GitHub Desktop.
Save maxim75/1050481 to your computer and use it in GitHub Desktop.
Plupload - handling POST request in ASP.NET
var chunk = Request.Form["chunk"] != null ? int.Parse(Request.Form["chunk"]) : 0;
var fileName = Request.Form["name"] ?? "";
//open a file, if our chunk is 1 or more, we should be appending to an existing file, otherwise create a new file
var fs = new FileStream(Server.MapPath("/files/" + fileName), chunk == 0 ? FileMode.OpenOrCreate : FileMode.Append);
//write our input stream to a buffer
var buffer = new Byte[Request.Files[0].InputStream.Length];
Request.Files[0].InputStream.Read(buffer, 0, buffer.Length);
//write the buffer to a file.
fs.Write(buffer, 0, buffer.Length);
fs.Close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment