我想使用按钮单击手动上传图像,然后将其发送到WebAPI并相应地获得响应。
这是.html页面
<script>
function getdata() {
var data = new FormData();
var files = $("#fileUpload").get(0).files;
var complexobj = {
filetosend: files[0]
};
var obj = { Mydata: complexobj };
var data2send = JSON.stringify(obj);
$.ajax({
type: "POST",
url: 'http://localhost:3469/api/values',
data: data2send,
contentType: "application/json; charset=utf-8",
dataType: "json",
processdata: false,
}).done(function (data) {
document.getElementById("label").innerHTML = data;
});
}
</script>
....
....
....
....
<input id="fileUpload" type="file" />
这是我的Mydata.cs类文件
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
namespace CNTKAzureTutorial01
{
public class Mydata
{
public Bitmap filetosend { get; set; }
}
}
这是我的ValuesController.cs文件
[SwaggerOperation("Create")]
[SwaggerResponse(HttpStatusCode.Created)]
public async Task<HttpResponseMessage> Post([FromBody]Mydata value)
{
Bitmap input = value.filetosend;
string[] output = await EvaluateCustomDNN(input);
return Request.CreateResponse(HttpStatusCode.OK, output);
}
我收到响应错误500,我尝试在Visual Studio中使用断点进行调试但仍然无法调试它。你能帮我吗?