我正在尝试使用 value ajax 上传器。http://valums.com/ajax-upload/ http://valums.com/ajax-upload/
我的页面上有以下内容:
var button = $('#fileUpload')[0];
var uploader = new qq.FileUploader({
element: button,
allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
sizeLimit: 2147483647, // max size
action: '/Admin/Home/Upload',
multiple: false
});
它确实发布到我的控制器,但 qqfile 始终为空。我尝试过这些:
public ActionResult Upload(HttpPostedFile qqfile)
AND
HttpPostedFileBase file = Request.Files["file"];
没有任何运气。
我找到了 ruby on Rails 的示例,但不知道如何在 MVC 中实现它http://www.jigsawboys.com/2010/10/06/ruby-on-rails-ajax-file-upload-with-valuem/ http://www.jigsawboys.com/2010/10/06/ruby-on-rails-ajax-file-upload-with-valum/
在萤火虫中我看到这个:http://localhost:61143/Admin/Home/Upload?qqfile=2glonglonglongname+-+Copy.gif http://localhost:61143/Admin/Home/Upload?qqfile=2glonglonglongname+-+Copy.gif
我想到了。这适用于 IE 和 Mozilla。
[HttpPost]
public ActionResult FileUpload(string qqfile)
{
var path = @"C:\\Temp\\100\\";
var file = string.Empty;
try
{
var stream = Request.InputStream;
if (String.IsNullOrEmpty(Request["qqfile"]))
{
// IE
HttpPostedFileBase postedFile = Request.Files[0];
stream = postedFile.InputStream;
file = Path.Combine(path, System.IO.Path.GetFileName(Request.Files[0].FileName));
}
else
{
//Webkit, Mozilla
file = Path.Combine(path, qqfile);
}
var buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
System.IO.File.WriteAllBytes(file, buffer);
}
catch (Exception ex)
{
return Json(new { success = false, message = ex.Message }, "application/json");
}
return Json(new { success = true }, "text/html");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)