I'm doing a simple c# generic handler that should receive a form post. Here's the form...
<form id="frmUploadImage" action="../Handlers/LocalImageUploadHandler.ashx" method="post" style="display: none">
<div>
<input style="display: none; margin-bottom: 20px" type="file" id="uploadImage" />
</div>
</form>
I have some code that, upon the click of a button invokes the click event of the input. When the input is loaded, the following is invoked (I can set a breakpoint and it gets here).
var jqxhr = $.post('../Handlers/LocalImageUploadHandler.ashx', $('#frmUploadImage').serialize())
.success(function() {
alert('worked');
})
.error(function() {
alert('failed');
});
It will show an alert for "failed". Server-side, it is calling this in the handler (I can verify that it is getting invoked by setting a breakpoint).
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/octet-stream";
var file = Convert.FromBase64String(context.Request.Form["uploadedFile"]);
//other stuff
}
What's interesting is that the context.Request.Form and context.Request.Files properties have no items in them, even though they are being sent. Nothing I've done has worked. I've tried posting with XHR, jQuery, etc. I've tried pulling the data out of the file upload control as a DataUrl and serializing it to a base64 encoded string and putting it in an ajax call. The handler will receive a post, but the data is being stripped.