Upload Large files(1GB)-ASP.net

2020-01-31 03:46发布

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.

I am using:

HIF.PostedFile.InputStream.Read(fileBytes,0,HIF.PostedFile.ContentLength)

before using:

File.WriteAllBytes(filePath, fileByteArray)

(doesnt go here but gives System.OutOfMemoryException exception)

Currently I have set the httpRuntime to:

executionTimeout="999999" maxRequestLength="2097151"(thats 2GB!) useFullyQualifiedRedirectUrl="true" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="5000" enableVersionHeader="true" requestLengthDiskThreshold="8192"

Also i have set maxAllowedContentLength="**2097151**" (guess its only for IIS7)

I have changed IIS connection timeout to 999,999 secs too.

I am unable to upload files of even 4578KB (Ajaz-Uploader.zip)

标签: c# .net
8条回答
Fickle 薄情
2楼-- · 2020-01-31 04:35

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;
}
查看更多
看我几分像从前
3楼-- · 2020-01-31 04:40

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

查看更多
登录 后发表回答