Skip to content

Instantly share code, notes, and snippets.

/Test

Created April 27, 2017 15:48
Show Gist options
  • Save anonymous/5610b421abad1733c9a359d6bff8a068 to your computer and use it in GitHub Desktop.
Save anonymous/5610b421abad1733c9a359d6bff8a068 to your computer and use it in GitHub Desktop.
StackOverflow Q43594950
<cfscript>
saveToDirec = "c:/somefolder/";
// boundary marker MUST match value used in actual cfhttp response
contentType = "multipart/related;boundary=MIME_Boundary;";
// Load and parse ByteArrayOutputStream returned by CFHTTP
bads = createObject("java", "javax.mail.util.ByteArrayDataSource").init(cfhttp.fileContent, contentType);
mp = createObject("java", "javax.mail.internet.MimeMultipart").init(bads);
// loop through parts
for (i = 0; i < mp.getCount(); i++) {
writeOutput("<br>Processing part["& i &"]");
bp = mp.getBodyPart( javacast("int", i));
// If this is a PDF, save it to a file.
// **** NOTE: Update directory path ****
if (!isNull(bp) && bp.isMimeType("application/pdf")) {
outputFile = createObject("java", "java.io.File").init(saveToDirec &"demo_savedfile_"& i &".pdf");
bp.saveFile(outputFile);
writeOutput("<br>Saved: "& outputFile.getAbsolutePath());
}
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment