My widget file viewer is not working properly.. what's wrong?

marielle.spiteri's picture
Blog Categories: 

What's wrong?

I use a widget File viewer in my forms/pages to display PDF files. Depending on the browser I use, my PDF file is not displayed correctly, or not at all, or its just available to download, for instance:

Or download is forced:

But it only happens on my server, it was working well in my Studio!


Why is my widget "File viewer" not showing my PDF file ? Why is it displaying its ASCII content instead? Why is my browser forcing the download instead of showing the view of my file?


It's most likely that you have an Apache in your environment.

The Bonita portal does not add a "Content-Type" header. Your Apache configuration is most likely forcing a "Content-Type" header that isn't 'application/pdf', and the file is displayed with that wrong "Content-Type", hence not displayed correctly.

How to check if you're in this configuration

Test the Bonita portal URL directly

If your form is a task form, connect to the following URL and confirm the PDF display is correct:

Use your browser developer tool (F12)

  • Open your developer tool (F12) and check the response to the request responsible for retrieving the "image" of the document. It's most likely forced to something else than "Content-Type: application/pdf", like "Content-Type: text/html"
  • Example:

Request: Method: GET URL: http://localhost:8080/bonita/portal/resource/taskInstance/MyProcessFileViewer/1.0/Step1FileViewer/API/formsDocumentImage?document=1 Response: (...) Content-Type: text/html (...)

And how to fix it

The answer depends on your Apache version and configuration.

The best approach is to contact your IT team to have them check your Apache configuration to check if somewhere in your configuration a default "Content-Type" is established in case there is none.

It happens that this type of configuration is sometimes made by your IT team in the Apache 'httpd.conf' file.

For instance, with Apache 2.2, the solution is to update the 'httpd.conf' and change the DefaultType by None:

# DefaultType is the default MIME type the server will use for a document # if it cannot otherwise determine one, such as from filename extensions. # If your server contains mostly text or HTML documents, "text/plain" is # a good value. If most of your content is binary, such as applications # or images, you may want to use "application/octet-stream" instead to # keep browsers from trying to display binary files as though they are # text. # DefaultType None

See official Apache 2.2 Documentation: Note: DefaultType None is only available in httpd-2.2.7 and later.

There you go!