I am getting error while sending base64 in ajax request using GET method. I can only use get method as shopify does not allow cross domain with any other method.
GET https://example.com/abc/uploadfile.php?callback=undefined&image=%5B%22data%3Aim
net::ERR_ABORTED 414 (Request-URI Too Long)
Here’s the code:
$.ajax({
type: "GET",
data: {
image: JSON.stringify(dataUrl.match(/.{1,3000}/g))
},
crossDomain: true,
contentType: 'application/json; charset=utf-8',
url: "example.com/uploadfile.php",
dataType: "jsonp",
jsonpCallback: function(data) {
console.log(data);
alert("success");
}
});
2
Answers
If it’s true that:
You have to do this cross-domain; and
Shopify only allows cross-domain ajax requests with GET (not POST); and
Your data is so long that the URI containing is is too long for your browser, their server, or some intermediary;
then your only option is not to do that. Instead, you might pass the data through a server under your control that will then send it on to Shopify using POST (since the Same Origin Policy is a browser thing).
You will need to use of App Proxy
With the app proxy you can send request to same domain, regardless weather it is post or get.
Shopify will automatically redirect your request to your application End Point.