在json中传递base64字节的图像数组给webApi

Passing base64 byte array of image in json to webApi

本文关键字:图像 数组 webApi 字节 base64 json      更新时间:2023-09-26

我已经将我通过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);
        }

所以谁都能看出问题出在哪里,需要做什么。

Thanks in advance.

为什么在URL和GET中发送图像?您应该在请求的正文中使用POST发送它。base64中的图像可能非常大,url可能会受到一些限制。看这个