Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting Uploadify to work with asp.net-mvc
    text
    copied!<p>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.</p> <p>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.</p> <p>Anyway this is my partial code:</p> <pre><code>&lt;% using ( Html.BeginForm( "Upload", "Document", FormMethod.Post, new { enctype = "multipart/form-data" } ) ) { %&gt; &lt;link type="text/css" rel="Stylesheet" media="screen" href="/_assets/css/uploadify/uploadify.css" /&gt; &lt;script type="text/javascript" src="/_assets/js/uploadify/swfobject.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/_assets/js/uploadify/jquery.uploadify.v2.1.0.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $("[ID$=uploadTabs]").tabs(); var auth = "&lt;% = Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %&gt;"; $('#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(); }); }); &lt;/script&gt; &lt;div id="uploadTabs"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#u-tabs-1"&gt;Upload file&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div id="u-tabs-1"&gt; &lt;div&gt; &lt;input id="fileInput" name="fileInput" type="file" /&gt; &lt;/div&gt; &lt;div style="text-align:right;padding:20px 0px 0px 0px;"&gt; &lt;input type="submit" id="btnSave" value="Upload file" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;% } %&gt; </code></pre> <p>Thanks very much for helping!</p> <p><strong>UPDATE</strong>:</p> <p>I have added a "onError" handler to the uploadify script to explore which error was happening as in the following sample</p> <pre><code>onError: function(event, queueID, fileObj, errorObj) { alert("Error!!! Type: [" + errorObj.type + "] Info [" + errorObj.info + "]"); } </code></pre> <p>and discovered that the info property contains <strong>302</strong>. I have also added the <strong>"method"</strong> parameter to uploadify with the value of <strong>'post'</strong>.</p> <p>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...</p> <pre><code>[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."); } </code></pre> <p>Can anybody provide some help please?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload