Problem with file upload using jquery on ie and chrome
I have this simple script
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Button ID="btnUploadFile" runat="server" Text="Button" />
<input id="File1" type="file" />
</asp:Content>
$(document).ready(function ()
{
$('#file_upload').fileUpload({
url: 'UploadHandler.ashx',
method: 'POST'
// autoUpload: false,
// onLoadAll: function (list)
// {
// __doPostBack('MainContent_UpdatePanel1', '');
// },
});
$('#File1').css({ 'position': 'absolute', 'z-index': '-100' }开发者_Python百科); //hack for chrome, in fx enough is jquery hide()
$('#MainContent_btnUploadFile').click(function ()
{
$('#File1').click();
return false;
});
});
and the http handler
public class UploadHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
HttpPostedFile uploadedfile = context.Request.Files[0];
}
public bool IsReusable
{
get
{
return false;
}
}
}
When I launch this code, in firefox is all ok. In the http handler there is my uploaded file. But in chrome I have exception, because Request.Files has no file. In internet explorer after selected file it is over. It never gets to the handler. Why the hell on diffrent browsers are that much diffrent results? The jquery upload plugin is located here http://aquantum-demo.appspot.com/file-upload What can I do with it? Example from plugin page for asp.net works ok on chrome. I think I wrote is in the same way like in this example, but it doesn't work.
In my experience, some browsers will send the file in context.Request.Files("<filename>").InputStream
Others will use context.Request.InputStream
I'm using http://valums.com/ajax-upload/ as the upload control
精彩评论