上传的WebAPI错误。 MIME多流的预期结束。 MIME多信息是不完整的 [英] WebAPI upload error. Expected end of MIME multipart stream. MIME multipart message is not complete

查看:291
本文介绍了上传的WebAPI错误。 MIME多流的预期结束。 MIME多信息是不完整的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注这个教程来支持文件上传的MVC4的的WebAPI的一部分:<一href=\"http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx\">http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx.

I've been following this tutorial to support file uploading as part of MVC4's WebAPI: http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx.

在我的控制器接收到请求时,它抱怨说,MIME多的信息是不完整的。。有没有人对如何调试这个任何提示?我试过在场外的机会还有别的东西看完它击中了处理程序之前流的位置重置为0。

When my controller receives the request, it complains that the 'MIME multipart message is not complete.'. Does anyone have any tips on how to debug this? I've tried resetting the stream's position to 0 on the off-chance there was something else reading it before it hit the handler.

我的HTML如下:

<form action="/api/giggl" method="post" enctype="multipart/form-data">
    <span>Select file(s) to upload :</span>
    <input id="file1" type="file" multiple="multiple" />
    <input id="button1" type="submit" value="Upload" />
</form>

和我的控制器Post方法是这样的:

and my controller's Post method like this:

    public Task<IEnumerable<string>> Post()
    {
        if (Request.Content.IsMimeMultipartContent())
        {
            Stream reqStream = Request.Content.ReadAsStreamAsync().Result;
            if (reqStream.CanSeek)
            {
                reqStream.Position = 0;
            }

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

            var task = Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(t =>
            {
                if (t.IsFaulted || t.IsCanceled)
                    Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception);

                var fileInfo = streamProvider.FileData.Select(i =>
                {
                    var info = new FileInfo(i.LocalFileName);
                    return "File uploaded as " + info.FullName + " (" + info.Length + ")";
                });
                return fileInfo;

            });
            return task;
        }
        else
        {
            throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "Invalid Request!"));
        }
    }

我缺少什么明显?>

Am I missing anything obvious?>

推荐答案

你可以尝试添加name属性到输入文件?

Can you try adding the "name" attribute to your input file?

<input name="file1" id="file1" type="file" multiple="multiple" />

这篇关于上传的WebAPI错误。 MIME多流的预期结束。 MIME多信息是不完整的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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