3

我正在尝试让Fine Uploader jQuery 示例正常工作。基本上它只是一种将文件从客户端页面上传到网络服务器的方法。

在项目的 GitHub 页面上有一个关于如何在服务器端设置文件流的示例。

我如何从脚本中调用这个 HttpPost endpoint?简单的 jQuery 示例如下所示:

$(document).ready(function () {
      $('#jquery-wrapped-fine-uploader').fineUploader({
        request: {
          endpoint: 'WhatToWriteHere??'
        },
        debug: true
      });
    });

那你在里面输入endpoint什么?我想它会是类似的东西Namespace.Namespace.ClassName.UploadMethod(),但我一直在摆弄它,但无法让它工作。使用 Firebug 进行调试时,出现以下错误:

405 Method Not Allowed  
[FineUploader] xhr - server response received for 0
The HTTP verb POST used to access path '/FineUploaderTest/Uploadfolder' is not allowed.

任何想法?

4

1 回答 1

4

您可以编写一个通用的 HttpHandler来处理文件上传:

public class UploadHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        var request = context.Request;
        var formUpload = request.Files.Count > 0;

        var xFileName = request.Headers["X-File-Name"];
        var qqFile = request["qqfile"];
        var formFilename = formUpload ? request.Files[0].FileName : null;

        var filename = xFileName ?? qqFile ?? formFilename;
        var inputStream = formUpload ? request.Files[0].InputStream : request.InputStream;

        var filePath = Path.Combine(context.Server.MapPath("~/App_Data"), filename);
        using (var fileStream = File.OpenWrite(filePath))
        {
            inputStream.CopyTo(fileStream);
        }

        context.Response.ContentType = "application/json";
        context.Response.Write("{\"success\":true}");
    }

    public bool IsReusable
    {
        get { return true; }
    }
}

接着:

$(document).ready(function () {
    $('#jquery-wrapped-fine-uploader').fineUploader({
        request: {
            endpoint: '/uploadhandler.ashx'
        },
        debug: true
    });
});
于 2013-01-15T09:03:44.873 回答