I'm passing the dataURL from JS in the vfp to the extensions class. I'm trying to store that image as an attachment to the custom object. The attachment is uploaded but when I try to open, a "file" (type of file: file) is downloaded which is unable to open. When I paste the dataURL in a browser, I'm able to view the image. So I think I'm making a mistake in the Blob.
imagedataURL --> data:image/png;base64,iVBORw...
public void uploadfile() {
string imagedataurl = ApexPages.currentPage().GetParameters().Get('imagedataurl');
System.debug(' DataURL : ' + imagedataurl);
Blob imageblob = Blob.valueOf(imagedataurl);
attachment a = new attachment();
a.ParentId = 'a0Oe000000XXXXXXXA';
a.Name = 'attachment';
a.Body = imageblob;
insert a;
}
Thanks in advance.