Reputation: 387
I am using Uploadify v3.1 for MVC3 C#.
My cshtml code is
<div class="container_24">
<input type="file" name="file_upload" id="file_upload" />
</div>
My js code is
$(document).ready(function () {
$('#file_upload').uploadify({
'method': 'post',
'swf': '../../Scripts/uploadify-v3.1/uploadify.swf',
'uploader': 'DashBoard/UploadFile'
});
});
And the controller code is
[HttpPost]
public ActionResult UploadFile(HttpPostedFileBase file)
{
// Verify that the user selected a file
if (file != null && file.ContentLength > 0)
{
// extract only the fielname
var fileName = Path.GetFileName(file.FileName);
// store the file inside ~/App_Data/uploads folder
var path = Path.Combine(Server.MapPath("~/Uploads"), fileName);
file.SaveAs(path);
}
// redirect back to the index action to show the form once again
return RedirectToAction("Index", "Home");
}
Now when i click the upload button it show two errors, sometime it show IO error and sometime it show HTTP 404 error for some file. what is wrong ? help me please ?
Upvotes: 2
Views: 2010
Reputation: 430
What size files are you uploading? Everything over 1MB or anything under?
Also what sort of 404 are you getting? If it's a 404.13 (file size error) then you're having the same problem I had. Good news. Because I fixed my problem. :)
If you're not sure what type the 404 is (Firebug will tell you), check your Windows event log and look in the "Application" log for a warning that looks like this:
If you've got both of these, then the problem is that IIS (which I'm assuming you're using) is not set up to allow big enough content requests.
Firstly, put this in your web config:
<system.webServer>
<security>
<requestFiltering>
<!-- maxAllowedContentLength = bytes -->
<requestLimits maxAllowedContentLength="100000000" />
</requestFiltering>
</security>
</system.webServer>
Then this, in "system.web":
<!-- maxRequestLength = kilobytes. this value should be smaller than maxAllowedContentLength for the sake of error capture -->
<httpRuntime maxRequestLength="153600" executionTimeout="900" />
Please pay attention to the notes provided - maxAllowedContentLength is in BYTES and maxRequestLength in KILOBYTES - big difference.
The maxAllowedContentLength value I provided will let you up load anything upto around 95MB.
This solved my version of this problem anyway.
Upvotes: 7