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

查看:541
本文介绍了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多的信息是不完整的。

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

我不知道,如果问题出在网页API或Flex。我发现一些相关的修正是没有影响(<一个href=\"http://stackoverflow.com/questions/12384544/multipart-form-post-using-asp-net-web-api\">Multipart形成POST使用ASP.Net的Web API ),以及最近的这一个(<一个href=\"http://stackoverflow.com/questions/10139052/mime-multipart-stream-mime-multipart-message-is-not-complete-error-on-webapi\">"MIME多部分流MIME多信息是不完整的&QUOT;上的WebAPI上传错误)。如果第二个环节也是如此,没有人知道它是否通过的NuGet是出的Web API的当前版本可用?讨论是在五月份,从的NuGet最新的版本是八月,所以我想这个修复程序已经部署,而不是我的问题的根本原因。

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问题下面报告说,它看起来像其他人证实了这一问题仍然在九月存在。

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不>不添加一个\\ r \\ n的MultiPartForm邮件的末尾

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.$c$cplex.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天全站免登陆