lundi 11 avril 2016

.net handler (ashx) for Fineuploader

I am looking at FineUploader for a DNN web site.

I have a basic handler that seems to work fine:

    public void ProcessRequest(HttpContext context)
    {
        try
        {
            var UserId = context.Request["userId"];
            var PortalId = context.Request["portalId"];
            //var UserAgent = context.Request["userAgent"];

            context.Response.ContentType = "text/plain";

            var tempPath = "~/Portals/" + PortalId + "/some-documents/users/" + UserId;
            var dirFullPath = context.Server.MapPath(tempPath);


            foreach (string s in context.Request.Files)
            {
                var file = context.Request.Files[s];
                var fileName = file.FileName;
                var fileExtension = file.ContentType;

                if (string.IsNullOrEmpty(fileName)) continue;
                var pathToSave_100 = HttpContext.Current.Server.MapPath(tempPath) + "\\" + fileName;
                file.SaveAs(pathToSave_100);

            }

            context.Response.StatusCode = (int) HttpStatusCode.OK;
            context.Response.Write("{\"success\":true}");

        }

        catch (Exception ex)
        {
            context.Response.Write("Error: " + ex.Message);
        }
    }

The problem is that there are no example .ashx type handlers in the github repo for FineUploader: http://ift.tt/1Q3B0Oz

I would like to know if anyone has a more comprehensive one? I am concerned about accommodating IE and returning proper error messages to the client.




Aucun commentaire:

Enregistrer un commentaire