This is a migrated thread and some comments may be shown as answers.

[Solved] Large file upload

0 Answers 49 Views
Upload
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kier
Top achievements
Rank 1
Kier asked on 07 Apr 2011, 06:34 PM
I know that the official way to handle large files is to up the IIS limit, but I was wondering if it would be possible to call the upload action without including the filestream in the call so that we could do our own file streaming using code like the following?


foreach (string file in Request.Files)
{
  if (Request.Files[file].HasFile())
  {
    var fileHeader = Request.Files[file];
    string path = AppDomain.CurrentDomain.BaseDirectory + "uploads/";
    string filename = Path.Combine(path, Path.GetFileName(fileHeader.FileName));
 
    var fileStream = new FileStream(filename, FileMode.OpenOrCreate);
    var fileChunk = new byte[32768];
 
    // Get the stream
    using (var requestStream = fileHeader.InputStream) // request.GetRequestStream())
    {
      int cbRead;
 
      // Grab a chunk
      while ((cbRead = fileHeader.InputStream.Read(fileChunk, 0, fileChunk.Length)) > 0)
      {
        // Append it to the file
        fileStream.Write(fileChunk, 0, cbRead);
      }
 
      fileStream.Close();
    }
  }
}

Tags
Upload
Asked by
Kier
Top achievements
Rank 1
Share this question
or