Click here to Skip to main content
15,887,998 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have created file uploader through MVC, jQuery, Ajax.But it is working
fine for 1-3kb(file size) only , for more size it is not working .Please help
how to upload lager size file

---html part--
HTML
<input type="file" name="bfile"  size="50" id="bfile"/>
<input type="butt

---AppAttachmentsController--controller code---
C#
public string file_upload(string file_name, string file_binary)
       {

           byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(file_binary);
           MemoryStream stream = new MemoryStream(byteArray);
           string path=Server.MapPath(Url.Content("~/upload/file"))+"\\"+file_name;
           using (var fileStream = new FileStream(path, FileMode.Create))
               stream.CopyTo(fileStream);

           return "1";
       }


-----jQuery, Ajax-----
 function AttachemtPost() {
    var file_name = $("#bfile").val();
    var data = "file_name=" + file_name;
    var file = document.getElementById('bfile').files[0];
    var file_binary = file.getAsBinary();
    var file_size = file.fileSize;
    var file_text = file.getAsText("");
    alert('file :' + file_binary);
    alert('file size:' + file_size);
    data = "file_name=" + file_name + "&file_binary=" + file_binary;
    ajaxlocalcall2(null, "POST", '@Url.Content("~/AppAttachments/file_upload")', data, "", "", "html", "oncontactinfosave");
}

-----------------------------------
Posted
Updated 22-May-12 20:12pm
v2
Comments
Sandeep Mewara 23-May-12 3:45am    
What error do you get? What exactly is the page displayed in case of failure?
dear.banerjee 24-May-12 3:48am    
No..error.when File more than 3-4 kb controller getting null or 1 or 2 garbage character

try this

C#
HttpPostedFile myFile = filUpload.PostedFile;
                int nFileLen = myFile.ContentLength;
                if (nFileLen == 0)
                {
                    lblOutput.Text = "There wasn't any file uploaded.";
                    return;
                }
 
Share this answer
 
Comments
dear.banerjee 24-May-12 3:49am    
where to write the line ?
nachiket03 24-May-12 3:53am    
you can write on click event of the upload button control
nachiket03 24-May-12 3:51am    
you can write on click event of the upload button control
Try this:

In web.config file increase the "maxRequestLength" property of HttpRunTime.
like

<httpRuntime maxRequestLength="1024000"/>
 
Share this answer
 
v2
Comments
nachiket03 24-May-12 3:11am    
does it works
dear.banerjee 24-May-12 3:49am    
I tried this also but not solve

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