Angularjs 通过web Api将文件上载到Azure会引发不支持的媒体类型异常?

Angularjs 通过web Api将文件上载到Azure会引发不支持的媒体类型异常?,angularjs,azure,asp.net-web-api,azure-storage-blobs,Angularjs,Azure,Asp.net Web Api,Azure Storage Blobs,我尝试使用Web Api和angular通过浏览器将文件上载到azure,我遵循了以下示例: 我从angular service发送请求(不确定这是否是正确的实现!): 文件是用户选择的文件数组 <input type="file" ngf-select="uploadFiles($files, $invalidFiles)" multiple accept="image/*" ngf-max-height="1000" ngf-max-size="3MB" /> 在他的实现中,

我尝试使用Web Api和angular通过浏览器将文件上载到azure,我遵循了以下示例:

我从angular service发送请求(不确定这是否是正确的实现!):

文件
是用户选择的文件数组

<input type="file" ngf-select="uploadFiles($files, $invalidFiles)" multiple accept="image/*" ngf-max-height="1000" ngf-max-size="3MB" />

在他的实现中,他没有定义发布在web api中的对象,这对我来说是不寻常的行为。因此,如何将文件传递到web API,以及以任何可以通过此
表单数据测试的格式传递文件?

根据您的描述,我已经按照您提供的代码示例构建了我的web API,我可以使其按预期工作。使用Postman进行测试时,需要将内容类型设置为
表单数据
,将数据类型设置为
文件
,如下所示:

根据您的JavaScript代码,您正在使用上载文件,同时
Request.Content.IsMimeMultipartContent
在Web API后端接收指定的内容
multipart/form数据

据我所知,对于一种简单的方法,您可以利用
Upload.Upload()
多部分/表单数据进行跨浏览器上传,如下所示:

HTML


javascript

var-app=angular.module('fileUpload',['ngFileUpload']);
app.controller('MyCtrl',函数($scope,Upload){
$scope.uploadFiles=函数(文件){
if(files&&files.length){
对于(var i=0;i
注意:有关更详细的示例,您可以按照中的使用示例进行操作

此外,您需要在
AzureStorageMultipartFormDataStreamProvider.cs
中更改
\u supportedMimeTypes
,如下所示:

private readonly string[]\u-supportedMimeTypes={“image/png”、“image/jpeg”、“image/jpg”}


此外,还有一个关于Http文件上传工作原理的讨论,您可以参考它。

您解决了这个问题了吗,有更新吗?
<input type="file" ngf-select="uploadFiles($files, $invalidFiles)" multiple accept="image/*" ngf-max-height="1000" ngf-max-size="3MB" />
if (!Request.Content.IsMimeMultipartContent("form-data"))
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }