ASP.NET Web API,从 Flex FileReference 上传时 MIME 多部分流意外结束 [英] ASP.NET Web API, unexpected end of MIME multi-part stream when uploading from Flex FileReference

查看:18
本文介绍了ASP.NET Web API,从 Flex FileReference 上传时 MIME 多部分流意外结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照 ASP.NET 上的教程,实现了一个 Web API 控制器方法来进行异步文件上传,如下所示:

Following the tutorial found on ASP.NET, implemented a Web API controller method for doing asynchronous file uploads that looks like this:

public 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);

    // Read the form data and return an async task.
    var task = Request.Content.ReadAsMultipartAsync(provider).
        ContinueWith<HttpResponseMessage>(t =>
        {
            if (t.IsFaulted || t.IsCanceled)
            {
                Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        });

    return task;
}

通过标准的多部分 HTML 表单上传文件非常有效.但是,当另一个开发人员尝试通过由 Flex 的 FileReference 类构造的多部分表单上传文件时,会引发错误:

Uploading a file via a standard multipart HTML form works perfectly. However, when another developer attempts to upload a file via multipart form constructed by Flex's FileReference class, an error is thrown:

MIME 多部分流意外结束.MIME 多部分消息不完整.

Unexpected end of MIME multipart stream. MIME multipart message is not complete.

我不知道问题出在 Web API 还是 Flex.我发现了一些没有影响的相关修复(Multipart formPOST 使用 ASP.Net Web API),以及最近的这个(MIME 多部分流.MIME 多部分消息不完整"在 webapi 上传时出现错误).如果第二个链接成立,有谁知道它是否在通过 Nuget 提供的当前版本的 Web API 中发布?讨论是在 5 月进行的,Nuget 的最新版本是 8 月,所以我认为此修复程序已经部署,并且不是我问题的根本原因.

I have no idea if the problem lies in Web API or Flex. I've found some sort of related fixes that had no affect (Multipart form POST using ASP.Net Web API), and more recently this one ("MIME multipart stream. MIME multipart message is not complete" error on webapi upload). If the second link holds true, does anyone know if it's out in the current release of Web API available via Nuget? The discussion was in May, the most recent release from Nuget was August, so I assume this fix was deployed already, and is not the root cause of my issue.

推荐答案

阅读您现有的研究并跟进 codeplex 问题报告说,看起来其他人确认此问题在 9 月份仍然存在.

Reading through your existing research and following through to the codeplex issue reported it looks like someone else confirmed this issue to still exist in September.

他们认为 MVC 4 无法在没有终止\r\n"的情况下解析上传.

They believe that MVC 4 fails to parse uploads without a terminating "\r\n".

这个问题很简单,但很难解决.问题是 Uploadify > 没有在 MultiPartForm 消息的末尾添加\r\n"

The issue is really simple but extremely hard to fix. The problem is that Uploadify does > not add an "\r\n" at the end of the MultiPartForm message

http://aspnetwebstack.codeplex.com/discussions/354215

可能值得检查 Flex 上传是否添加了\r\n"

It may be worth checking that the Flex upload adds the "\r\n"

这篇关于ASP.NET Web API,从 Flex FileReference 上传时 MIME 多部分流意外结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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