2

Trying to send base64 string for an image in the query param, and Getting 400 Bad Request. Tried the following:-

Gone through this question on stack overflow. According to this, chrome can have more characters in the URL than what I am sending as imageBytes(29527 characters),

What is the maximum possible length of a query string ?

Instructions in the following Question also didn't help

Passing base64 encoded strings in URL ?

Here is my code

It works fine if i am sending a hard coded string like this "something" in place of form.imageBytes

$scope.submit = function(){
  var form = {};
  form.name = document.getElementById("recipient-name").value;
  form.desc = document.getElementById("message-text").value;
  form.owner = document.getElementById("message-text2").value;
  form.imageBytes = $scope.asdf;

  var data = JSON.stringify(form);

    debugger;
    var postString = "http://cos1plp:7030/tcw/interestgroup/addInterestGroups?name="+form.name+"&desc="+form.desc+"&owner="+form.owner+"&imageBytes="+form.imageBytes;

    $http.post(postString)

        .success(function (data, status, headers, config) {
        $scope.headers = headers();
        console.log('Response Headers:' + headers());
        })

        .error(function (data, status, headers, config) {
        $scope.headers = headers();
        });

}
Community
  • 1
  • 1
Ankur Marwaha
  • 1,613
  • 2
  • 15
  • 30
  • 1
    Don't send it in the query string. You're sending a post for a reason, usually that reason is to send a post body and avoid the limitations of a query string parameter. – gforce301 Apr 21 '17 at 16:04

1 Answers1

0

Base64 strings can contain special characters, namely + / = signs. You'll need to encode them into a valid url string. Try adding this to your code:

data = data.replace(/\+/g, '%2B');
data = data.replace(/\//g, '%2F');
data = data.replace(/\=/g, '%3D');