UI からアップロードされたファイルを受け入れる post メソッドを持つ Web API を作成しています。
public async Task<List<string>> PostAsync()
{
if (Request.Content.IsMimeMultipartContent("form-data"))
{
string uploadPath = HttpContext.Current.Server.MapPath("~/uploads");
var streamProvider = new MyStreamProvider(uploadPath);
await Request.Content.ReadAsMultipartAsync(streamProvider);
return streamProvider.FileData
.Select(file => new FileInfo(file.LocalFileName))
.Select(fi => "File uploaded as " + fi.FullName + " (" + fi.Length + " bytes)")
.ToList();
}
else
{
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid Request!");
throw new HttpResponseException(response);
}
}
次に、郵便配達員による上記のアクションへのリクエストを投稿します。content-type ヘッダーを multipart/form-data に設定しましたが、アクションの実行中にエラーが発生します。エラーメッセージの本文は次のとおりです。
「無効な 'HttpContent' インスタンスが提供されました。'boundary' パラメータを持つ 'multipart' content-type ヘッダーがありません。\r\nパラメータ名: content」
私は郵便配達員のヘッダーに行きましたが、リクエストヘッダーのコンテンツタイプがapplication-jsonに設定されていることがわかりました。
誰でも私を助けることができますか?