Skip to main content

This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.

Support Article

Screenshot attachment does not display at the receiver end

SA-59253

Summary



When sending an email with an attachment (screenshot), the attachment does not display at the receiver end. This occurs when the application has 10 nodes.


Error Messages



The linked image cannot be displayed. The file may have been moved, renamed, or deleted. Verify that the link points to the correct file and location.


Steps to Reproduce



Include a local action to send an email in a Rich Text Editor (RTE).


Root Cause



A defect in Pegasystems’ code or rules.

In a multinode environment, images render incorrectly.



Resolution



Perform the following local-change:

1. To obtain images on all nodes, enable a check to fetch the image from the cache else retrieve the image directly from the database.

2. Save As the @baseclass.SendEmailNotification (Pega-IntegrationEngine:07-10-26) activity to the custom application ruleset and add a new Java Step 2.

3. Include the below code in the new Java step activity. try { 
String imgExp = "((<[iI][mM][gG][\\s\\S]*?)|([iI][mM][aA][gG][eE][dD][aA][tT][aA][\\s\\S]*?))((\\s[sS][rR][cC])(\\s*=\\s*[\"|']))(\\S+)([\"|'][\\s\\S]*?>)"; 
java.util.regex.Pattern referencePattern = java.util.regex.Pattern.compile(imgExp); 
String message = tools.getParamValue("Message"); 
java.util.regex.Matcher match = referencePattern.matcher(message); 

StringBuffer updatedMarkup = new StringBuffer(message.length() + 1024); 
while (match.find()) { 

String originalURL = match.group(7); 
// avoid references to remote images, i.e. that don't have http://, ftp:// in them 
if (originalURL.indexOf(":") == -1) { 
boolean fileExists = true; 
PRFile prfile = null; 
String fileName = originalURL.substring(originalURL.lastIndexOf("/") + 1, originalURL.lastIndexOf(".")); 
String fileExt = originalURL.substring(originalURL.lastIndexOf(".") + 1); 
String folderName = pega_rules_string.whatComesAfterLast(pega_rules_string.whatComesBeforeLast(originalURL, '/'), '/'); 

//if (!filesInZip.contains(originalURL)) { 
try { 

prfile = pega.getStaticContentUtils().getResolvedFile(originalURL); 
} catch (java.io.IOException e) { 
fileExists = false; 


if (prfile == null) fileExists = false; 

if (!fileExists) { 
ClipboardPage cpResult = null; 
HashStringMap hsmKeys = new HashStringMap(); 
hsmKeys.putString("pxObjClass", "Data-Content-Image"); 
hsmKeys.putString("pyFileName", fileName); 
hsmKeys.putString("pyFileType", fileExt); 
hsmKeys.putString("pyFilePath", "/" + folderName + "/"); 

try { 
PRThread thread = (PRThread) ThreadContainer.get(); 

Database db = (Database) thread.getDatabase(); 
cpResult = db.open(hsmKeys, false); 


} catch (DatabaseException dbEx) { 
oLog.error("Database Exception reading Data-Content-Image instance from database :" + dbEx.getMessage(), dbEx); 

if (cpResult != null) { 
String pyFileSource = cpResult.getString("pyFileSource"); 
String aFilePath = "file://web:/StaticContent" + originalURL.substring(2); 

boolean isSucces = false; 

com.pega.pegarules.priv.util.HTTPPrepOutputStream hposExtracted = null; 
try { 
hposExtracted = new com.pega.pegarules.priv.util.HTTPPrepOutputStream(new PRFile(aFilePath), false, false); 


byte buffer[] = null; 

try { 
String sFileContent = pyFileSource
byte bContent[] = null; 
int nContentLength
if (hsmKeys.getString("pxObjClass").equals("Data-Content-Image")) { 
bContent = Base64Util.decode(sFileContent.getBytes("UTF-8")); 
nContentLength = bContent.length; 
} else { 

bContent = sFileContent.getBytes("UTF-8"); 
nContentLength = bContent.length + PRFileUtil.UTF8_BOM.length; 
buffer = com.pega.pegarules.priv.factory.ByteArrayFactory.acquire(nContentLength); 
buffer[0] = PRFileUtil.UTF8_BOM[0]; 
buffer[1] = PRFileUtil.UTF8_BOM[1]; 
buffer[2] = PRFileUtil.UTF8_BOM[2]; 
System.arraycopy(bContent, 0, buffer, PRFileUtil.UTF8_BOM.length, bContent.length); 
bContent = buffer; 

hposExtracted.write(bContent, 0, nContentLength); 

isSucces = true; 
} catch (Exception ioEx) { 
String sErrorMsg = StringUtils.concat(StringUtils.ASIS, "Error while writing ", 
ioEx, "\n", ioEx.getMessage()); 
oLog.error(sErrorMsg); 

if (hposExtracted != null) { 
hposExtracted.cleanupAfterFailure(); 

isSucces = false; 
} finally { 
if (buffer != null) { 
com.pega.pegarules.priv.factory.ByteArrayFactory.release(buffer); 



if (isSucces) { 

hposExtracted.close(); 
} else { 
if (oLog.isDebugEnabled()) { 
oLog.debug(StringUtils.concat(StringUtils.ASIS, "Error while writing ", aFilePath)); 

hposExtracted.cleanupAfterFailure(); 

} catch (Exception ioEx) { 
String sErrorMsg = StringUtils.concat(StringUtils.ASIS, "Error while writing ", 
ioEx, "\n", ioEx.getMessage()); 
oLog.error(sErrorMsg); 

if (hposExtracted != null) { 
hposExtracted.cleanupAfterFailure(); 

} finally { 







} catch (Exception e) { 
// add any log statements if needed 
}



 
Suggest Edit

Published November 29, 2018 - Updated October 8, 2020

Did you find this content helpful? Yes No

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

We'd prefer it if you saw us at our best.

Pega Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice
Contact us