Upload Large files(1GB)-ASP.net

后端 未结 8 1350
北海茫月
北海茫月 2020-12-05 21:08

I need to upload large files of at least 1GB file size. I am using ASP.Net, C# and IIS 5.1 as my development platform.

相关标签:
8条回答
  • 2020-12-05 21:49

    For IIS 6.0 you can change AspMaxEntityAllowed in Metabase.xml, but I don't think it's as straight forward in IIS 5.1.

    This link may help, hope it does:

    http://itonlinesolutions.com/phpbb3/viewtopic.php?f=3&t=63

    0 讨论(0)
  • 2020-12-05 21:53

    I think you should use Response.TransmitFile, this method does not load in web server memory the file, it streams the file without using web server resources.

    if (Controller.ValidateFileExist())
            {
                ClearFields();
                Response.Clear();
                Response.ContentType = "text/plain";
                Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", "FileNAme.Ext"));
                Response.TransmitFile(FileNAme.Ext);
                Response.End();
                Controller.DeleteFile();
            }
    
    0 讨论(0)
  • 2020-12-05 21:56

    I googled and found - NeatUpload


    Another solution would be to read the bytes on the client and send it to the server, the server saves the file. Example

    Server: in Namespace - Uploader, class - Upload

    [WebMethod]
    public bool Write(String fileName, Byte[] data)
    {
        FileStream  fs = File.Open(fileName, FileMode.Open);
        BinaryWriter bw = new BinaryWriter(fs); 
        bw.Write(data);
        bw.Close();
    
        return true;
    }
    

    Client:

    string filename = "C:\..\file.abc";
    Uploader.Upload up = new Uploader.Upload();
    FileStream  fs = File.Create(fileName); 
    BinaryReader br = new BinaryReader(fs);
    
    // Read all the bytes
    Byte[] data = br.ReadBytes();
    up.Write(filename,data);
    
    0 讨论(0)
  • 2020-12-05 21:57

    I know it is an old question, but still unanswered.

    So this is what you have to do:

    In you web.config file, add this in :

        <!-- 3GB Files / in kilobyte (3072*1024) -->
        <httpRuntime targetFramework="4.5" maxRequestLength="3145728"/>
    

    and this under

    <security>
        <requestFiltering>
    
          <!-- 3GB Files / in byte (3072*1024*1024) -->
          <requestLimits maxAllowedContentLength="3221225472" />
    
        </requestFiltering>
    </security>
    

    You see in the comment how this works. In one you need to have the sie in bytes and in the other one in kilobytes. Hope that helps.

    0 讨论(0)
  • 2020-12-05 22:02

    Check this blog entry about large file uploads. It also has a few links to some discussion forums that can shed some light on this as well. The suggestion is to use custom HttpHandler for that or custom Flash/Silverlight control.

    0 讨论(0)
  • 2020-12-05 22:10

    We have an app that occasionally needs to upload 1 and 2 GB files, so has been running into this as well. After much research, my conclusion is that we need to implement the previously mentioned NeatUpload, or something like it.

    Also, be aware that

    <requestLimits maxAllowedContentLength=.../>
    

    is measured in bytes, while

    <httpRuntime maxRequestLength=.../>
    

    is measured in kilobytes. So your values should look more like this:

    <httpRuntime maxRequestLength="2097151"/>
    ...
    <requestLimits maxAllowedContentLength="2097151000"/>
    
    0 讨论(0)
提交回复
热议问题