【发布时间】:2011-04-17 01:03:20
【问题描述】:
我正在尝试让 Uploadify 与我的网站一起使用,但即使在文件发送到服务器之前,我也会收到一个通用的“HTTP 错误”(我这样说是因为 Fiddler 没有向我的控制器显示任何发布请求。
我可以正确浏览要上传的文件。队列中正确填充了要上传的文件,但是当我点击提交按钮时,队列中的元素变为红色并显示 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>
<% } %>
非常感谢您的帮助!
更新:
我在 uploadify 脚本中添加了一个“onError”处理程序,以探索发生了哪个错误,如下例所示
onError: function(event, queueID, fileObj, errorObj) {
alert("Error!!! Type: [" + errorObj.type + "] Info [" + errorObj.info + "]");
}
发现 info 属性包含 302。我还添加了 "method" 参数以使用 'post' 的值进行上传。
我包含我的控制器操作代码以供参考。我已经阅读了很多关于 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.");
}
有人可以帮忙吗?
【问题讨论】:
-
没有机会获得这方面的帮助? :(
标签: asp.net-mvc file-upload uploadify