我已将通过 jQuery 上传的图像转换为 base64 字节数组/字符串。
借助代码:
function readImage(input) {
debugger;
if (input.files && input.files[0]) {
var FR = new FileReader();
var a = null;
FR.onload = function (e) {
array = e.target.result;
};
FR.readAsDataURL(input.files[0]);
}
我现在通过 json 将数组传递到我的 Web Api 并遇到问题。
我的 json 调用如下:
$.getJSON('api/TestImage' + '/' + JSON.stringify(array))
.done(function (data) {
//doSomething
});
我的行动是:
public IHttpActionResult TestImage(String id)
{
return Ok(id);
}
谁能告诉我问题是什么以及需要做什么。
提前致谢..
最佳答案
为什么要在 URL 和 GET 中发送图像?您应该在请求正文中使用 POST 发送它。 Base64 中的图像可能非常大,并且您可能会遇到 url 的一些限制。看this
关于c# - 将 json 中的图像的 base64 字节数组传递给 webApi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24837441/