Search code examples
javascriptangularjsimagebase64http-status-code-400

Unable to send base 64 Image data to server with angular js


I am trying to send Base64 Image data to the server with $http Post request, It is working for lower resolution images (upto 100KB) But not working for higher resolution images (trying for 6MB file).

Getting Error: 400 Bad Request.

    $http({url:ServerURL,method: "POST",
            params: {imageData:base64_imgData}
    }).then(function(response) {
      console.log(response.data);
      console.log(response.status);
    },function(response) {
       console.log(response.data);
       console.log(response.status);
    });

Please help how to overcome with this issue.


Solution

  • Thanks for the answer Jay, your answer helped me.

    Issue resolved by using Jquery Ajax request

    $.ajax({
       type: "POST",
       url: ServerURL,
       data: { 
             imageData:base64_imgData
       },
       cache: false,
       contentType: "application/x-www-form-urlencoded",
       success: function (result) {
           console.log("Success");
       }
    });
    

    I think sending base 64 image data to server is not recommended for large size images, this is a very good way to run out of memory. better to use files and send the file.