简体   繁体   中英

Asynchronously receiving a file uploaded via ajax

I'm using a jquery file uploader , which is damn simple to use.

Basically, what it does is, it creates an <iframe> and adds a <form method="POST" enctype="multipart/form-data" action="settings.action">

And then, it creates a <input type="file"> inside that form and submits the form to the given action setting.

$('#sampleFile').ajaxfileupload({
  action:'AsyncFileUploadHandler.ashx' // submits the file to this url
});

And this is my handler:

<%@ WebHandler Language="C#" Class="AsyncFileUploadHandler" %>
using System;
using System.Web;
public class AsyncFileUploadHandler : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Write("Hello World");
        // I don't know how to grap the uploaded file here.
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}

I've seen MVC examples but not Web Forms. Googling really gave me nothing. And it seems that there is no duplicate of this question on SO.

So, what should I do in my handler to get the file contents?

我将name属性添加到文件控件中,仅添加context.Request.Files[0] ,它可以正常工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM