I'm working on integrating a feature that enables users to save a png created on a canvas element into the WordPress media library, or at least onto the server (which is an initial step before sharing the image on Facebook, as it requires a valid image URL).
Until now, I've been using JavaScript for everything, and am attempting to save the image to the server using an AJAX call. This is what my AJAX looks like so far:
$(document).on('click','.facebook',function(e){
var image = document.getElementById("canvas");
var imageURL = image.toDataURL();
$.ajax({
type: "POST",
url: "http://myexample.com",
data: {
imgBase64: imageURL
}
}).done(function(o) {
console.log('saved');
});
I'm also unsure about what should be included in the url field... I tried using the path for images in my actual media library, but encountered a "permission denied" error when trying to execute this.
Could someone provide assistance?