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();
});
}
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');
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.