How to upload image using Ajax request?

How do I upload multiple files/images from the client to the server using Java?

  • Here is a sample of the code I am using:  function cropImageSave(){          var imageData = $('#item-image').attr('src');          var imageName = $('#upl_input').val();                 alert("imageData" + imageData);         alert("imageName" + imageName);           $.ajax({              type: 'post',              url: 'cropImage.htm',              processData: false,              contentType: application/json,              data:{imageData1:JSON.stringify(imageData)},              success:function(result){                  alert(result);              }           }); With this code, I get imageData and imageName in Base64 format, but I am unable to send it to a controller in http://en.wikipedia.org/wiki/Spring_Framework.

  • Answer:

    function(img) {       i = new Image();       i.src = img;       $(this).appned(i);     }, $.ajax({    type: 'post',    dataType: 'image/gif',     error: function(error, txtStatus) {          }   }); Idea is to use new Image() instance to add the image and send it to Ajax

Venu Gopal Reddy Muvva at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.