0

I have a requirement where I have to take a screenshot of multiple pages and store them in documents on the click of a button. I have everything working perfectly on a windows machine. But when I try it on a mac I get a REEGEX too complicated error when trying to screenshot a specific page. I am using HTML2CANVAS to take the screenshot, and then pass the blob value to my controller.

Here is the relevant controller code.

    transient public string strImageBlob {get;set;}
    transient public string strImagename {get;set;} 

    public void captureImage()
        {
            folderId = [SELECT ID 
                            FROM Folder 
                            WHERE NAME = 'DOC Folder'].Id;
            Document d = new Document(); 
            d.Name = strImagename+'.png';         
            d.Body = EncodingUtil.base64Decode(strImageBlob.replaceFirst('data:image/png;base64,','')); 
//Error occurs on the above line ^^^^^^^
            d.ContentType = 'image/png';
            d.FolderId = folderId;
            d.IsPublic = true;
            insert d;
            RelateListSnapCntrl.saveRecIdinCookie(d.Id);
            system.debug('\n--d---'+d);
        }

The error occurs in the line indicated above. It seems to occur only in a Mac (or possibly in computers with higher resolution monitors). Is there a way I can handle this error?

Error:

enter image description here

4
  • 1
    Can you post the EXACT error message seen as part of your question please? Just edit the question to add the detail.
    – Phil W
    Nov 4, 2019 at 16:55
  • if string you are operating on is more than 1 MB, this error will occur
    – cropredy
    Nov 4, 2019 at 18:43
  • 1
    @PhilW I have added the error msg to the question. Nov 6, 2019 at 15:52
  • @cropredy Is there any way I can work around this? Nov 6, 2019 at 16:06

1 Answer 1

3

A typical reason for regex too complicated is when the target string is > 1 MB

The String class has three methods:

  • someString.replace(target,replacement)
  • someString.replaceAll(regex,replacement)
  • someString.replaceFirst(regex,replacement)

Your application is trying to replace data:image/png;base64, with simply ,

If your application is OK with replacing all of data:image/png;base64, with ,, then use the replace(target,replacement) method as it doesn't use regex

Example:

someString.replace('data:image/png;base64,',',');
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .