Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Everyone,

I have to develop a web page in which user will upload large files say ranging 600 MB to 2 GB.

Also, do let me know what factors like (bandwidth etc) may impact the speed to file upload.

What I have tried:

Currently i am using normal file upload control for small files.

I checked with this piece of code

VB.ASPX

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="VB.aspx.vb" Inherits="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    Select File :- <input type="file" name="postedFile" />
    <input type="button" id="btnUpload" value="Upload" />
        <br />
        <br />
    <progress id="fileProgress" style="display: none"></progress>
    <hr />
    <span id="lblMessage" style="color: Green"></span>
          <script type="text/javascript" src="jquery.min-1.8.3.js"></script>
    <script type="text/javascript">
        $("body").on("click", "#btnUpload", function () {
            $.ajax({
                url: 'HandlerVB.ashx',
                type: 'POST',
                data: new FormData($('form')[0]),
                cache: false,
                contentType: false,
                processData: false,
                success: function (file) {
                    $("#fileProgress").hide();
                    $("#lblMessage").html("" + file.name + " has been uploaded.");
                },
                xhr: function () {
                    var fileXhr = $.ajaxSettings.xhr();
                    if (fileXhr.upload) {
                        $("progress").show();
                        fileXhr.upload.addEventListener("progress", function (e) {
                            if (e.lengthComputable) {
                                $("#fileProgress").attr({
                                    value: e.loaded,
                                    max: e.total
                                });
                            }
                        }, false);
                    }
                    return fileXhr;
                }
            });
        });
    </script>
    </form>
</body>
</html>


with below Handler

HandlerVB.ashx

<%@ WebHandler Language="VB" Class="HandlerVB" %>

Imports System
Imports System.IO
Imports System.Net
Imports System.Web
Imports System.Web.Script.Serialization

Public Class HandlerVB : Implements IHttpHandler
    
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        'Check if Request is to Upload the File.
        If context.Request.Files.Count > 0 Then
            
            'Fetch the Uploaded File.
             Dim postedFile As HttpPostedFile = context.Request.Files(0)
            
            'Set the Folder Path.
            'Dim folderPath As String = context.Server.MapPath("~/Uploads/")
           
            'Set the File Name.
            Dim fileName As String = Path.GetFileName(postedFile.FileName)
            
            'Save the File in Folder.
            postedFile.SaveAs(folderPath + fileName)
            
            'Send File details in a JSON Response.
            Dim json As String = New JavaScriptSerializer().Serialize(New With {
                .name = fileName
            })
            context.Response.StatusCode = CInt(HttpStatusCode.OK)
            context.Response.ContentType = "text/json"
            context.Response.Write(json)
            context.Response.End()
        End If
    End Sub
 
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class



When i am uploading 100 MB file with in my network it takes 4 minutes to upload and approximately 7 minutes to upload from outside network. However, whenever uploading 600 MB or more size file it is not getting uploaded.

Web.config

<configuration>

    <system.web>
      <httpRuntime maxRequestLength="2147483647" executionTimeout="3600" enableVersionHeader="false" />	
      <compilation debug="true" targetFramework="4.0" />
    </system.web>

 <system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="2147483647" />
      </requestFiltering>
   </security>
 </system.webServer>
</configuration>


kindly help, how to resolve it or any other method to achieve it.
Posted
Updated 10-Aug-20 21:11pm
v2
Comments
OriginalGriff 11-Aug-20 2:25am    
And?
What is the problem?
What have you tried?
Where are you stuck?
What help do you need?

Use the "Improve question" widget to edit your question and provide better information.
Magic Wonder 11-Aug-20 2:44am    
Done. Kindly suggest

1 solution

First off, maxRequestLength is in KB, not bytes: and since it's an integer there is a good chance that it overflows.
You probably need to revise the maxAllowedContentLength as well - that's in Bytes this time.

Try
HTML
<httpRuntime maxRequestLength="2147483" executionTimeout="3600" enableVersionHeader="false" />
And
HTML
<security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="2147483647" />
    </requestFiltering>
</security>

You may need to check with your hoisting service to make sure they don;t have any limits which override those settings - some of the cheaper ones do.
It's probably worth a look here as well: Jon Galloway - Large file uploads in ASP.NET[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900