Click here to Skip to main content
14,360,938 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello

I've been trying to upload Mp4 videos which have large space in my MVC project and it gives me an error, it only allows videos that are smaller then 3MB. Even if i change the if statement below e.g
if(videofile.ContentLength< 104857600)
still it doesn't solve my problem.

Please help

What I have tried:

videofilesDB db =new videofilesDB();
        GET: MVCupload
        public ActionResult Index()
        {
           return View();
        }
        public ActionResult Index(HttpPostedFileBase videofile)
        {
            if(videofile!=null)
            {
                string filename = Path.GetFileName(videofile.FileName);
                if(videofile.ContentLength< 104857600)
                {
                    videofile.SaveAs(Server.MapPath("/Videofiles/" + filename));

                    string mainconn = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
                    SqlConnection sqlconn = new SqlConnection(mainconn);
                    string sqlquery = "insert into [dbo].[videofiles] values (@Vname,@Vpath)";
                    SqlCommand sqlcomm = new SqlCommand(sqlquery, sqlconn);
                    sqlconn.Open();
                    sqlcomm.Parameters.AddWithValue("@Vname", filename);
                    sqlcomm.Parameters.AddWithValue("@Vpath","/Videofiles/" + filename);
                    sqlcomm.ExecuteNonQuery();
                    sqlconn.Close();
                    ViewData["Message"] = "Record Saved Successfully!";

                }
            }
            return View("Index");
Posted
Updated 19-Sep-18 4:26am
Rate this:
Please Sign up or sign in to vote.

Solution 1

A lot of webservers like IIS have this maximum request length property you need to adjust. This setting prevents requests larger to be bounced in the IIS pipeline even before it hits your code. You can adjust this setting in your website properties in IIS, and in your web.config.

By the way, a while ago I wrote this article about storing images in a SQL Server database using entity framework, Storing Images in SQL Server using EF and ASP.NET[^]

Have a read, it saves you a lot code like above
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

Try this;

In your web.config file in the <system.web> section add
<!--The default size is 4096 kilobytes (4 MB). MaxValue is 2147483647 KB (2 TB)-->
<!-- 100 MB in kilobytes -->
<httpRuntime maxRequestLength="102400" />


and in the <system.webserver> section add

<security>
   <requestFiltering>
       <!--The default size is 30000000 bytes (28.6 MB). MaxValue is 4294967295 bytes (4 GB)-->
       <!-- 100 MB in bytes -->
        <requestLimits maxAllowedContentLength="104857600" />
    </requestFiltering>
</security>
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100