简体   繁体   English

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

[英]Passing base64 byte array of image in json to webApi

I have converted the image that I upload through jQuery into base64 byte array/String. 我已将通过jQuery上传的图像转换为base64字节数组/字符串。

With the help of code : 借助代码:

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]);
   }

I am now passing the array through json to my web Api and having problem. 我现在将数组通过json传递到我的Web Api并遇到问题。

My json call is like: 我的json呼叫就像:

 $.getJSON('api/TestImage' + '/' + JSON.stringify(array))
            .done(function (data) {
                //doSomething
            });

My action is : 我的动作是:

       public IHttpActionResult TestImage(String id) 
        {
            return Ok(id);
        }

So can any one tell what is the problem and what need to be done. 因此,任何人都可以说出问题所在以及需要做什么。

Thanks in advance.. 提前致谢..

Why do you send image in URL and GET? 为什么要使用URL和GET发送图像? You should send it using POST in body of the request. 您应该使用请求正文中的POST发送该消息。 Image in base64 could be pretty large and you could reach some limitations for url. base64中的图像可能很大,您可能会遇到url的一些限制。 Look at this 这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM