Hey all
okay with the additional work i did with Jsoup, I have made a update to this problem.
See the below code snippet for a Jsoup solution to this problem.
Reference for Camunda docker with Jsoup: Replacing Http-Connector with Jsoup usage
binaryFileDownload-Jsoup.bpmn (3.8 KB)
create a downloadFile.js
file and deploy it along with the above bpmn file.
The downloadFile.js has the following content:
function downloadFile(fileUrl)
{
with (new JavaImporter(org.jsoup, java.io.BufferedInputStream))
{
var doc = Jsoup.connect(fileUrl)
.method(Java.type('org.jsoup.Connection.Method').GET)
.timeout(30000)
.ignoreContentType(true)
.execute()
var bodyStream = doc.bodyStream()
return bodyStream
}
}
function saveFile(fileStream, fileName, mimeType)
{
var file = Java.type('org.camunda.bpm.engine.variable.Variables')
.fileValue(fileName)
.file(fileStream)
.mimeType(mimeType)
.create()
execution.setVariable(fileName, file)
}
function downloadAndSaveFile(fileUrl, fileName, mimeType)
{
var file = downloadFile(fileUrl)
saveFile(file, fileName, mimeType)
}
downloadAndSaveFile('http://www.pdf995.com/samples/pdf.pdf', 'mypdf.pdf', 'application/pdf')
The downloadAndSaveFile()
function is a helper function hat saves you some time. and lets you download the file and save it as a Camunda File
type all in a single function.
Lots of fun use cases!