download documents from business data

1
0
-1

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

1 answer

1
0
-1

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

Comments

Submitted by smarouani on Wed, 03/07/2018 - 12:35

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!

Submitted by joe.pappas on Wed, 03/07/2018 - 21:11

Which version of the product are you using? Community or Subscription?

Submitted by smarouani on Thu, 03/08/2018 - 14:37

I use Community version.

Submitted by joe.pappas on Tue, 03/13/2018 - 18:36

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)

Submitted by smarouani on Tue, 04/17/2018 - 11:22

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!

Submitted by joe.pappas on Tue, 04/17/2018 - 15:17

In Subscription you can use the File Viewer widget to view files:
https://documentation.bonitasoft.com/bonita/7.6/widgets#toc25

Submitted by smarouani on Tue, 04/17/2018 - 15:39

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!

Submitted by smarouani on Tue, 04/17/2018 - 15:39

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!

Submitted by joe.pappas on Tue, 04/17/2018 - 15:40

Good to know! Thanks for the update

Submitted by the.shirini on Mon, 11/30/2020 - 22:40

Cool thumbs_up.png

Notifications