Sha*_*eKm 40 asp.net asp.net-mvc asp.net-mvc-3
我正在尝试使用valums ajax uploader.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
});
Run Code Online (Sandbox Code Playgroud)
它会发布到我的控制器,但qqfile始终为null.我试过这些:
public ActionResult Upload(HttpPostedFile qqfile)
AND
HttpPostedFileBase file = Request.Files["file"];
Run Code Online (Sandbox Code Playgroud)
没有运气.
我在rails上找到了ruby的例子,但不确定如何在MVC中实现它 http://www.jigsawboys.com/2010/10/06/ruby-on-rails-ajax-file-upload-with-valum/
在firebug中我看到: http:// localhost:61143/Admin/Home/Upload?qqfile = 2glonglonglongname + - + Copy.gif



Sha*_*eKm 68
我想到了.这适用于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");
}
Run Code Online (Sandbox Code Playgroud)