This is our code for this (using ajax and jquery):
var image = new Image();
image.onload = function () {
screenResolution = JSON.parse(screenResolution);
const width = (screenResolution.x);
const height = (screenResolution.y);
canvas.width = width;
canvas.height = height;
context.drawImage(image, 0, 0);
const imageConvBase = canvas.toDataURL("image/jpeg", 1);
$.ajax({
url: "https://api.imgur.com/3/upload",
method: "POST",
timeout: 0,
headers: {
Authorization: 'Client-ID {REMOVED FOR STACKOVERFLOW}'
},
data: {
image: imageConvBase,
type: "base64",
},
processData: false,
mimeType: "multipart/form-data",
contentType: false,
error: function(response) {
console.log("AJAX Error: " + JSON.stringify(response));
},
success: function(response) {
if (response.success) {
console.log(response.data.link);
}
}
});
}
image.src = imgURL;
He throws me the following error:
[1124/143540.368:INFO:CONSOLE(0)] "Access to XMLHttpRequest at 'https://api.imgur.com/3/upload' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."
I tried everything which is possible on localhost, but we cannot run it on a server so it has to be localhost