Hi,
I have a process and subprocess which manage pdf documents stored in business data, and I want to display these documents same way as servlet DocumentImageServlet.
A REST API extension which implements RestApiController is the best way to do this? or can I extend DocumentImageServlet in order to get documents from business data?
thanks!
Saoussen
You can use the case document REST API to retrieve documents. For more information see:
https://documentation.bonitasoft.com/bonita/7.5/bpm-api#toc17
Thank you for you answer, but my documents informations are in database. So to use case document REST API, I should load them in process to have access?
I tried to implement a Rest api extension as following:
def String pdfResponse
context.resourceProvider.getResourceAsStream(“pdf/test.pdf”).withStream { InputStream s →
pdfResponse = s.getText()
}
responseBuilder.with {
withResponse(pdfResponse)
withMediaType("application/pdf")
withCharacterSet("ISO-8859-5")
build()
}
but I have these errors:
Error: FDICT bit set in flate stream: 120, 63
Error: Invalid XRef stream header
Have you any idea about this?
thank you!
Which version of the product are you using? Community or Subscription?
Right, I don’t believe REST API Extensions are supported in Community. In any case, file reading is beyond the scope of Bonitasoft. Here is a code snippet I used to read a file on the file system in a REST API Extension using the Subscription version of Bonita. This is just straight up Java file reading code:
String fileAndPath = "C:\\temp\\attachments\\" + fileLoc File file = new File(fileAndPath) Path source = Paths.get(fileAndPath) String mimeType = Files.probeContentType(source) FileInputStream fis = new FileInputStream(file) byte[] bytes = new byte[fis.available()] fis.read(bytes)
Hi Joe, thank you for your answer.
It’s possible to add REST API Extensions with Community version, but without using Studio. we should create a zip with files Index.groovy and page.properties then import it into portal.
Now I’m using Subscription, and I have the same problem with your code.
In fact browser display pdf file but with empty pages ( it works fine with other types like xml).
I tried to extend DocumentDownloadServlet but i can’t access to bdm, BusinessObjectDAOFactory returns ClassNotFoundException.
any help?
Thanks!
In Subscription you can use the File Viewer widget to view files:
https://documentation.bonitasoft.com/bonita/7.6/widgets#toc25
Same problem with File Viewer, displayed PDF is empty.
But I fixed this issue with the following code:
*File doc = new File("fileAndPath"); responseBuilder.with { withAdditionalHeader("Content-Disposition", "inline; filename=" + doc.getName()) withMediaType("application/pdf") withCharacterSet("ISO-8859-5") withResponse(doc.getText("ISO-8859-5")) build() }*
It was an encoding issue.
Thanks!
Same problem with File Viewer, displayed PDF is empty.
But I fixed this issue with the following code:
*File doc = new File("fileAndPath"); responseBuilder.with { withAdditionalHeader("Content-Disposition", "inline; filename=" + doc.getName()) withMediaType("application/pdf") withCharacterSet("ISO-8859-5") withResponse(doc.getText("ISO-8859-5")) build() }*
It was an encoding issue.
Thanks!
Good to know! Thanks for the update