Upload Large files(1GB)-ASP.net

后端 未结 8 1351
北海茫月
北海茫月 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 22:11

    Try copying without loading every thing in the memory :

    public void CopyFile()
    {
        Stream source = HIF.PostedFile.InputStream; //your source file
        Stream destination = File.OpenWrite(filePath); //your destination
        Copy(source, destination);
    }
    
    public static long Copy(Stream from, Stream to)
    {
        long copiedByteCount = 0;
    
        byte[] buffer = new byte[2 << 16];
        for (int len; (len = from.Read(buffer, 0, buffer.Length)) > 0; )
        {
            to.Write(buffer, 0, len);
            copiedByteCount += len;
        }
        to.Flush();
    
        return copiedByteCount;
    }
    
    0 讨论(0)
  • 2020-12-05 22:11

    Setting maxRequestLength should be enough for uploading files larger than 4mb, which is the default limit for HTTP request size. Please make extra sure that nothing is overriding your config file.

    Alternatively you can check the async upload provided by Telerik, which uploads files by 2mb chunks and effectively can bypass the ASP.NET request size limitation.

    0 讨论(0)
提交回复
热议问题