I am trying to crop/resize user profile images using the jQuery plugin crop.js which sends user images as Base64 via Ajax to my controller:
$.ajax({
type: "post",
dataType: "json",
url: "${g.createLink(controller: 'personalDetail', action:'uploadUserImage')}",
data: { avatar: canvas.toDataURL() }
});
But I'm unable to decode this Base64 string to an image:
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAYAAAA+VemSAAAgAEl...=='
How can I save the Base64 string as an image on my server?
decodeBase64()on the encoded stringiVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAYAAAA+VemSAAAgAEldirectly to get the byte array and then create the file as shown in answers.