Click here to Skip to main content
15,888,031 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 3:26am

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
 
Share this answer
 
v2
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>
 
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