如何在非MVC ASP.NET应用程序中使用服务器上的Fine Uploader [英] How to use Fine Uploader server-side in a non-MVC ASP.NET application

查看:45
本文介绍了如何在非MVC ASP.NET应用程序中使用服务器上的Fine Uploader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET(不是MVC)项目的aspx页面中的标记中具有以下上载器代码:

I have the following Fine Uploader code in markup in an aspx page in ASP.NET (not MVC) project:

<link href="../js/fineuploader/fineuploader-3.5.0.css" rel="stylesheet">
<script type="text/javascript" src="../js/fineuploader/fineuploader-3.5.0.js"></script>
<script type="text/javascript">
   $(document).ready(function () {
      var uploader = new qq.FineUploader({
         element: $('#fine-uploader')[0],
         request: {  /* <-- THIS IS WHAT I NEED TO FIGURE OUT */
            endpoint: 'server/handleUploads'
         },
         autoUpload: true,
         multiple: false,
         text: {
            uploadButton: '<asp:Button ID="fineUploadButton" runat="server" CssClass="button" style="width:6;5" Text="Browse" />'
         },
         validation: {
            allowedExtensions: ['mp3', 'wav']
         }
      });
   });
</script>

对于客户端,这很好.我已经修改了fineuploader.css以得到我想要的外观(主要是).完成客户端部分后,我只需要通过处理request endpoint部分来在后台代码中进行处理即可.

For the client side piece, this works fine. I've modified the fineuploader.css to get the exact look I want (mostly). With the client side piece being done I just need to handle this in my code-behind by handling the request endpoint piece.

我已经在github页面上查看了几个示例,但是对于ASP,没有非MVC的示例.这些示例中,即使最简单的示例也涉及创建一个新类并从Controller类继承.由于我不是使用MVC制作此站点,因此如何处理服务器方面的问题?

I've viewed several examples on the github page, but for ASP there are no non-MVC examples. Even the simplest of these examples involve creating a new class and inheriting from the Controller class. Since I'm not doing this site with MVC, how can I handle the server side aspect of this?

我的客户端部分非常完整,如有必要,我可以提供有关服务器端代码和组织的更多信息.

My client side piece is pretty much complete, and I can supply more info on my server side code and organization if necessary.

推荐答案

处理Fine Uploader发送的请求相当简单.默认情况下,所有上传请求都是多部分编码的POST请求.默认情况下,所有参数也以表单字段的形式出现在请求有效负载中.

Handling the requests sent by Fine Uploader is fairly trivial. All upload requests, by default, are multipart encoded POST requests. By default, all parameters are also present in the request payload as form fields.

我不是ASP.NET开发人员,但是在ASP.NET中处理MPE请求应该并不难.实际上,在大多数服务器端语言中,这是微不足道的.这是一些应处理此类请求的代码的示例:

I am not an ASP.NET developer, but it shouldn't be too difficult to handle MPE requests in ASP.NET. In fact, this is fairly trivial in most server-side languages. Here's an example of some code that should handle such a request:

using System.Diagnostics;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;

public class UploadController : ApiController
{
    public async Task<HttpResponseMessage> PostFormData()
    {
        // Check if the request contains multipart/form-data.
        if (!Request.Content.IsMimeMultipartContent())
        {
            throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
        }

        string root = HttpContext.Current.Server.MapPath("~/App_Data");
        var provider = new MultipartFormDataStreamProvider(root);

        try
        {
            // Read the form data.
            await Request.Content.ReadAsMultipartAsync(provider);

            // This illustrates how to get the file names.
            foreach (MultipartFileData file in provider.FileData)
            {
                Trace.WriteLine(file.Headers.ContentDisposition.FileName);
                Trace.WriteLine("Server file path: " + file.LocalFileName);
            }
            return Request.CreateResponse(HttpStatusCode.OK);
        }
        catch (System.Exception e)
        {
            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
        }
    }

}

请注意,您的服务器端代码还必须返回有效的JSON响应. Fine Uploader的服务器端自述文件中对此进行了详细说明. .在MSDN上有一篇文章描述了在中处理JSON. NET应用程序.也许JsonConvert类在这里是必需的.

Note that your server-side code must also return a valid JSON response. This is described more in Fine Uploader's server-side readme. There is an article on MSDN that describes dealing with JSON in .NET apps. Perhaps the JsonConvert class is required here.

您可以在 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆