我想讓Uploadify與我的網站一起工作,但即使在文件發送到服務器之前我也會收到一個通用的「HTTP錯誤」(我之所以這樣說是因爲Fiddler會這樣做不顯示任何郵寄請求到我的控制器獲取Uploadify與asp.net-mvc一起工作
我可以正確瀏覽上傳的文件隊列正確地填充上傳的文件,但是當我點擊提交按鈕時,隊列中的元素會變成紅色說HTTP錯誤
反正這是我的部分代碼:
<% 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>
<% } %>
非常感謝您的幫助!
UPDATE:
我已經加入了「的onError」處理器的uploadify腳本來探討哪些錯誤是怎麼回事如下面的示例
onError: function(event, queueID, fileObj, errorObj) {
alert("Error!!! Type: [" + errorObj.type + "] Info [" + errorObj.info + "]");
}
中,發現該信息屬性包含。我還添加了「方法」參數以上傳至值爲'帖子'。
我包括我的控制器操作代碼的信息。我已經看了很多帖子關於uloadify,似乎我可以使用具有以下簽名的動作......
[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.");
}
任何人能提供一些幫助嗎?
沒有機會得到這方面的幫助?:( – Lorenzo 2010-09-27 18:33:59