multipart/form-data リクエストをアクション (ファイルのアップロード) に送信していますが、ルートで指定された URL に ID を持つアクションに送信しています:
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}/{action}",
defaults: new {action = "Index", id = RouteParameter.Optional }
);
投稿先の URL:/api/Contacts/1/Photo
アクション:
[HttpPost]
public HttpResponseMessage Photo(int id)
{
var task = this.Request.Content.ReadAsStreamAsync();
task.Wait();
Stream requestStream = task.Result;
/* ... */
}
id パラメーターを使用すると、次のエラーが発生しますNo 'MediaTypeFormatter' is available to read an object of type 'Int32' with the media type 'multipart/form-data'.
。id パラメーターがないと、正常に動作します。
この回答hereでMediaTypeFormatter を試しましたが、URL から ID を取得していないようで、 を使用して取得しようとするとクラッシュしFirstDispositionNameOrDefault("id")
ます。ルート URL で指定された ID を取得して、アクションの ID パラメータにバインドする方法はありますか?