-
-
Save anonymous/5610b421abad1733c9a359d6bff8a068 to your computer and use it in GitHub Desktop.
StackOverflow Q43594950
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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