You must Sign In to post a response.
  • Category: .NET

    Unable to upload 2gb file

    Hi,

    I am trying to upload 2 GB file on to a file location.
    I have the following code in .cs file

    if (FileUpload1.HasFile && FileUpload1.FileBytes.Length < 2147483)
    {
    try
    {
    string filename = Path.GetFileName(FileUpload1.FileName);


    string SaveLocation = Server.MapPath("UploadedFiles") + "\\" + filename;
    FileUpload1.PostedFile.SaveAs(SaveLocation);

    Response.Write("The file has been uploaded.");
    }
    catch (Exception ex)
    {
    throw ex;
    }

    following settings in web.config file:-
    <configuration>
    <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.5">
    <assemblies>
    <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5" maxRequestLength="2097152" executionTimeout="32247"/>

    </system.web>
    <runtime>
    <gcAllowVeryLargeObjects enabled="true" />
    </runtime>
    <system.webServer>
    <security>
    <requestFiltering>
    <requestLimits maxAllowedContentLength="2147483648" />

    </requestFiltering>
    </security>
    </system.webServer>
    </configuration>


    still iam getting the following error:-

    Exception of type 'System.OutOfMemoryException' was thrown.

    Let me know if anyone has solution for this problem.
  • #766476
    Hi,

    As per error details "System.OutOfMemoryException" you don't have enough space to save that file in your local system, recheck the space in your local system if you think there is no proper space delete some files and try to reload it again, if you still face the same problem let us know.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #766481
    "Exception of type 'System.OutOfMemoryException' was thrown"
    problem usually occurs when some process such as loading huge data to memory stream and your system memory is not capable of storing so much of data. Try clearing temp folder by giving the command

    start -> run -> %temp%

  • #766484
    Hi,

    Thanks for the reply. I have more space on my disk around 236 Gb. So I dont know where it went wrong since there is enough space on disk.Please let me know if any one has any other solutions

  • #766488
    You are using following for runtime
    < httpRuntime targetFramework="4.5" maxRequestLength="2097152" executionTimeout="32247"/ >

    You have to add one more property "requestLengthDiskThreshold" and also change the values. In the config file you have to add the following.
    Can you try the following

    < httpRuntime maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647"/ >

    By Nathan
    Direction is important than speed

  • #766493
    Hi

    try this code

    Add this code in Web.config-

    <system.web>
    <httpRuntime executionTimeout="2400" maxRequestLength="40960" />
    system.web>

    or

    <configuration>
    <system.web>
    <httpRuntime maxRequestLength="2097151" />
    </system.web>
    </configuration>


    Or

    <system.web>
    <httpRuntime executionTimeout="110" maxRequestLength="40000" />
    </system.web>




    The maximum size you can set in ASP.NET is 2097151Kb = 2Gb.

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #766494
    Hi

    you can go through below link for large file upload


    "weblogs.asp.net/jongalloway/large-file-uploads-in-asp-net"

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #766505
    Please check can you put chunks of data to upload the file. One of my resource I will give a referral link as the problem is different from it but it gives some idea

    http://www.dotnetspider.com/resources/45904-Error-ORA-01460-unimplemented-or-unreasonable-conversion-requested.aspx.

    using webclient to upload a file to server
    http://www.dotnetspider.com/resources/46124-How-to-Upload-a-file-to-ftp-server-through-a-WebClient-Using-C.aspx

    using ftp client to upload a file to server
    http://www.dotnetspider.com/resources/46128-Upload-and-Download-a-File-to-Ftp-server-through-FTPClient-Using-C.aspx

    SRI RAMA PHANI BHUSHAN KAMBHAMPATI

  • #766510
    Hi,
    Try enabling 3GB switch of your server computer from boot.ini file, which helps to use lots/maximum of its memory.
    Follow steps given in below URL to enable/disable it:
    http://scorpion.tordivel.no/help/GettingStarted/3gswitch.htm
    Find discussion over server memory management using 3GB switch over here:
    https://blogs.technet.microsoft.com/askperf/2007/03/23/memory-management-demystifying-3gb/

  • #766602
    while uploading file system uses asp.net assigned memory, By default ASP.NET is allowed 60% of available memory, You can change that value to, say 80% to give ASP.NET more room, but this is not recommend. Consider other options, like uploading file in chunks etc (you can increase it in asp.net process model memory, it Configures the ASP.NET process model settings on a Microsoft Internet Information Services (IIS) Web server)
    see given link
    https://msdn.microsoft.com/en-us/library/7w2sway1(v=vs.100).aspx
    OR
    One solution would be to use MultipartFormDataStreamProvider instead of the MultipartMemoryStreamProvider to avoid the out of memory exception during the call, see below snippet

    Request.Content.ReadAsMultipartAsync(..)

    see below link
    http://stackoverflow.com/questions/23142064/uploading-file-to-server-throws-out-of-memory-exception

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


  • Sign In to post your comments