1

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..

Rohit Paul
  • 336
  • 1
  • 3
  • 13
  • What is the name of the controller that has that action? You're missing the controller name in the API call, i.e api/controller/action. Assuming you're using the default routing definition, of course. – Sameer Singh Jul 19 '14 at 06:40
  • TestImage is the controller name and I guess in api call there is no compulsion for action. The WebApiConfig manages it. As it is managing for rest of my Action. – Rohit Paul Jul 19 '14 at 08:26
  • Either rename your action above to `Get(string id)` or change the HTTP request URL in your jQuery to `'api/TestImage/TestImage'` – Sameer Singh Jul 22 '14 at 16:37

1 Answers1

0

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

Community
  • 1
  • 1
Jan Barta
  • 450
  • 2
  • 8