Hello,
I am trying to get Uploadify to work with my site but I am getting a generic "HTTP Error" even before the file is sent to the server (I say this because Fiddler does not show any post request to my controller.
I can browse correctly for the file to upload. The queue is correctly populated with the file to upload but when I hit on the submit button the element in the queue get a red color and say HTTP Error.
Anyway this is my partial code:
<% using ( Html.BeginForm( "Upload", "Document", FormMethod.Post, new { enctype = "multipart/form-data" } ) ) { %>
<link type="text/css" rel="Stylesheet" media="screen" href="/_assets/css/uploadify/uploadify.css" />
<script type="text/javascript" src="/_assets/js/uploadify/swfobject.js"></script>
<script type="text/javascript" src="/_assets/js/uploadify/jquery.uploadify.v2.1.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("[ID$=uploadTabs]").tabs();
var auth = "<% = Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>";
$('#fileInput').uploadify({
uploader: '/_assets/swf/uploadify.swf',
script: '/Document/Upload',
folder: '/_uploads',
cancelImg: '/_assets/images/cancel.png',
auto: false,
multi: false,
scriptData: { token: auth },
fileDesc: 'Any document type',
fileExt: '*.doc;*.docx;*.xls;*.xlsx;*.pdf',
sizeLimit: 5000000,
scriptAccess: 'always', //testing locally. comment before deploy
buttonText: 'Browse...'
});
$("#btnSave").button().click(function(event) {
event.preventDefault();
$('#fileInput').uploadifyUpload();
});
});
</script>
<div id="uploadTabs">
<ul>
<li><a href="#u-tabs-1">Upload file</a></li>
</ul>
<div id="u-tabs-1">
<div>
<input id="fileInput" name="fileInput" type="file" />
</div>
<div style="text-align:right;padding:20px 0px 0px 0px;">
<input type="submit" id="btnSave" value="Upload file" />
</div>
</div>
</div>
<% } %>
Thanks very much for helping!
UPDATE:
I have added a "onError" handler to the uploadify script to explore which error was happening as in the following sample
onError: function(event, queueID, fileObj, errorObj) {
alert("Error!!! Type: [" + errorObj.type + "] Info [" + errorObj.info + "]");
}
and discovered that the info property contains 302. I have also added the "method" parameter to uploadify with the value of 'post'.
I am including my controller action code for information. I have read many posts regarding uloadify and it seems that I can use an action with the following signature...
[HttpPost]
public ActionResult Upload(string token, HttpPostedFileBase fileData) {
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(token);
if (ticket!=null) {
var identity = new FormsIdentity(ticket);
if(identity.IsAuthenticated) {
try {
//Save file and other code removed
return Content( "File uploaded successfully!" );
}
catch ( Exception ex ) {
return Content( "Error uploading file: " + ex.Message );
}
}
}
throw new InvalidOperationException("The user is not authenticated.");
}
Can anybody provide some help please?