gpt4 book ai didi

asp.net - MVC Valums Ajax Uploader - IE 不会在 request.InputStream 中发送流

转载 作者:行者123 更新时间:2023-12-01 22:37:32 24 4
gpt4 key购买 nike

我正在使用 Valums Ajax uploader 。使用以下代码,一切都在 Mozilla 中运行良好:

查看:

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
});

Controller :

public ActionResult Upload(string qqfile)
{
var stream = Request.InputStream;
var buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);

var path = Server.MapPath("~/App_Data");
var file = Path.Combine(path, qqfile);
File.WriteAllBytes(file, buffer);

// TODO: Return whatever the upload control expects as response
}

在这篇文章中得到了回答:

MVC3 Valums Ajax File Upload

但是问题是这在 IE 中不起作用。我确实找到了这个,但我不知道如何实现它:

IE doesn't send the stream in "request.InputStream" ... instead get the input stream through the HttpPostedFileBase from the Request.Files[] collection

此外,这里显示了这个人是如何做到的,但我不确定如何更改我的项目:

Valum file upload - Works in Chrome but not IE, Image img = Image.FromStream(Request.InputStream)

//This works with IE
HttpPostedFileBase httpPostedFileBase = Request.Files[0]

as HttpPostedFileBase;

无法弄清楚这一点。请帮忙!谢谢

最佳答案

我明白了。这适用于 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");
}

关于asp.net - MVC Valums Ajax Uploader - IE 不会在 request.InputStream 中发送流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4888632/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com