简体   繁体   中英

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.

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.

My json call is like:

 $.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? You should send it using POST in body of the request. Image in base64 could be pretty large and you could reach some limitations for url. Look at this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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