Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. APS.Net 2.0 Large File Download

APS.Net 2.0 Large File Download

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netsysadminperformancetutorial
6 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Are Jay
    wrote on last edited by
    #1

    I have a pre-existing web application that moves files through HTTPS protocol between client and server. I have create an AJAX upload ( over 2 years ago so my knowledge of AJAX at the time was limited). Now I am re-visiting the application because I used the traditional methods for downloading a file ( code snippet below ). We have noticed that downloads of files that exceed 1 gig are killing our web server. My questions are:   -How to handle a chunked downloads so I am not loading every bit into memory then sending it.   -Has anyone used a purchased asp.net control that handles both Uploads/Downloads of large file(s) that they would recommend using.

    try
    {
    if (File.Exists(fullFilePath))
    {
    using (StreamReader _streamReader = new StreamReader(fullFilePath))
    {
    using (Stream _stream = _streamReader.BaseStream)
    {
    Response.Clear();
    Response.AddHeader("content-disposition",
    String.Format("attachment;filename={0}", Path.GetFileNameWithoutExtension(fullFilePath)));
    Response.Charset = "";
    Response.Cache.SetCacheability(HttpCacheability.Public);
    Response.ContentType = DataAccess.GetMIMEType(Path.GetExtension(fullFilePath));
    Response.BufferOutput = false;

        byte\[\] \_buffer = new byte\[1024\];
        int \_counter = \_stream.Read(\_buffer, 0, 1024);
        while (\_counter > 0)
        {
          Response.OutputStream.Write(\_buffer, 0, 1024);
          \_counter = \_stream.Read(\_buffer, 0, 1024);
        }
    
        Response.End();
    
      }
    }
    

    }
    }
    catch (Exception)
    { }

    All comments will be helpful and appreciated, thank you.

    I'm listening but I only speak GEEK.

    N A 2 Replies Last reply
    0
    • A Are Jay

      I have a pre-existing web application that moves files through HTTPS protocol between client and server. I have create an AJAX upload ( over 2 years ago so my knowledge of AJAX at the time was limited). Now I am re-visiting the application because I used the traditional methods for downloading a file ( code snippet below ). We have noticed that downloads of files that exceed 1 gig are killing our web server. My questions are:   -How to handle a chunked downloads so I am not loading every bit into memory then sending it.   -Has anyone used a purchased asp.net control that handles both Uploads/Downloads of large file(s) that they would recommend using.

      try
      {
      if (File.Exists(fullFilePath))
      {
      using (StreamReader _streamReader = new StreamReader(fullFilePath))
      {
      using (Stream _stream = _streamReader.BaseStream)
      {
      Response.Clear();
      Response.AddHeader("content-disposition",
      String.Format("attachment;filename={0}", Path.GetFileNameWithoutExtension(fullFilePath)));
      Response.Charset = "";
      Response.Cache.SetCacheability(HttpCacheability.Public);
      Response.ContentType = DataAccess.GetMIMEType(Path.GetExtension(fullFilePath));
      Response.BufferOutput = false;

          byte\[\] \_buffer = new byte\[1024\];
          int \_counter = \_stream.Read(\_buffer, 0, 1024);
          while (\_counter > 0)
          {
            Response.OutputStream.Write(\_buffer, 0, 1024);
            \_counter = \_stream.Read(\_buffer, 0, 1024);
          }
      
          Response.End();
      
        }
      }
      

      }
      }
      catch (Exception)
      { }

      All comments will be helpful and appreciated, thank you.

      I'm listening but I only speak GEEK.

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      I assume you don't want to, or can't, just place a link to the file on your page? What about making a temp copy and giving a link to that?


      only two letters away from being an asset

      1 Reply Last reply
      0
      • A Are Jay

        I have a pre-existing web application that moves files through HTTPS protocol between client and server. I have create an AJAX upload ( over 2 years ago so my knowledge of AJAX at the time was limited). Now I am re-visiting the application because I used the traditional methods for downloading a file ( code snippet below ). We have noticed that downloads of files that exceed 1 gig are killing our web server. My questions are:   -How to handle a chunked downloads so I am not loading every bit into memory then sending it.   -Has anyone used a purchased asp.net control that handles both Uploads/Downloads of large file(s) that they would recommend using.

        try
        {
        if (File.Exists(fullFilePath))
        {
        using (StreamReader _streamReader = new StreamReader(fullFilePath))
        {
        using (Stream _stream = _streamReader.BaseStream)
        {
        Response.Clear();
        Response.AddHeader("content-disposition",
        String.Format("attachment;filename={0}", Path.GetFileNameWithoutExtension(fullFilePath)));
        Response.Charset = "";
        Response.Cache.SetCacheability(HttpCacheability.Public);
        Response.ContentType = DataAccess.GetMIMEType(Path.GetExtension(fullFilePath));
        Response.BufferOutput = false;

            byte\[\] \_buffer = new byte\[1024\];
            int \_counter = \_stream.Read(\_buffer, 0, 1024);
            while (\_counter > 0)
            {
              Response.OutputStream.Write(\_buffer, 0, 1024);
              \_counter = \_stream.Read(\_buffer, 0, 1024);
            }
        
            Response.End();
        
          }
        }
        

        }
        }
        catch (Exception)
        { }

        All comments will be helpful and appreciated, thank you.

        I'm listening but I only speak GEEK.

        A Offline
        A Offline
        AlexeiXX3
        wrote on last edited by
        #3

        To download a file, just give them a link as the previous post suggested Or do you have any special requirements?

        Alexei Rodriguez

        A 1 Reply Last reply
        0
        • A AlexeiXX3

          To download a file, just give them a link as the previous post suggested Or do you have any special requirements?

          Alexei Rodriguez

          A Offline
          A Offline
          Are Jay
          wrote on last edited by
          #4

          Restrictions:   -Firewall restrictions will not allow me to pass specific file types.   -Upon upload the file is appended with a hashed value as a file extension (to prevent execution of uploaded files).   -Currently I have a getFile.aspx?file-id=[id] that returns the file. My understanding of a hyperlink via [filename] vs. [getFile.aspx]:   -[filename]: allows IIS to handle the transfer of the file (more efficient of the 2 choices).   -[getFile.aspx]: is not registered with IIS so it is managed at the code level. Is my understanding correct?

          I'm listening but I only speak GEEK.

          A 1 Reply Last reply
          0
          • A Are Jay

            Restrictions:   -Firewall restrictions will not allow me to pass specific file types.   -Upon upload the file is appended with a hashed value as a file extension (to prevent execution of uploaded files).   -Currently I have a getFile.aspx?file-id=[id] that returns the file. My understanding of a hyperlink via [filename] vs. [getFile.aspx]:   -[filename]: allows IIS to handle the transfer of the file (more efficient of the 2 choices).   -[getFile.aspx]: is not registered with IIS so it is managed at the code level. Is my understanding correct?

            I'm listening but I only speak GEEK.

            A Offline
            A Offline
            AlexeiXX3
            wrote on last edited by
            #5

            AreJay wrote:

            -Firewall restrictions will not allow me to pass specific file types.

            What would happen if you change the extension of files befre being downloaded via a hyperlink??

            Alexei Rodriguez

            A 1 Reply Last reply
            0
            • A AlexeiXX3

              AreJay wrote:

              -Firewall restrictions will not allow me to pass specific file types.

              What would happen if you change the extension of files befre being downloaded via a hyperlink??

              Alexei Rodriguez

              A Offline
              A Offline
              Are Jay
              wrote on last edited by
              #6

              This would work but I still run into the content/type restrictions which could be changed prior to download. This creates a new issues:   -How to update filename and file type once it file reaches the client's PC. I am unable to rely on the client to have the ability to rename the file (half the time they don't know where it went once it was downloaded). I would accomplish his if I used an ActiveX control on the client's PC. Not an ideal solution but still plausible. I would prefer purchasing a control that handles all of this for me. I don't have allot of time available to me for this project and am looking for a quick fix. I also need to update the Upload functionality to allow multiple files and folder uploading so my thoughts where to purchase a control that kills multiple birds with one stone. Thanks for all your assistance in helping me come to a solution.

              I'm listening but I only speak GEEK.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups