how to only accept ".pdf" format for file upload in bonitasoft ?

1
0
-1

i use bonita soft 2022.2

i want the upload widget accept only pdf extension, how to specify that ?

and how to use the property "Error on upload holder" in the right panel of the upload widget ?

1 answer

1
0
-1

Hi,

you can create your own custom widget from the upload widget and add a property to configure the accept attribute the

<input type="file" accept="{{ properties.accept }}" .../>

The Error on upload holder can be bound to a variable to display an error message to your users if the upload goes wrong. By using the Hidden property on a text by example. Here is a small example

For a server side validation, you will have to customize the bonita webapp web.xml file from the Tomcat Bundle. It should be possible to define a specific servlet (and its servlet-mapping) with the desired SupportedExtensions parameter.

    <servlet>
        <servlet-name>pdfUploadServlet</servlet-name>
        <servlet-class>org.bonitasoft.console.common.server.servlet.TenantFileUploadServlet</servlet-class>
        <init-param>
            <param-name>SupportedExtensions</param-name>
            <param-value>pdf</param-value>
        </init-param>
         <init-param>
            <param-name>ContentType</param-name>
            <param-value>json</param-value>
        </init-param>
    </servlet>
   ...
   <servlet-mapping>
        <servlet-name>pdfUploadServlet</servlet-name>
        <url-pattern>/API/pdfUpload</url-pattern>
    </servlet-mapping>

HTH
Romain

Comments

Submitted by webDev on Sat, 03/04/2023 - 06:58

1- I’ve done this before, I’ve already added "accept" attribute , but this is just a front side validation, the user can easily change the file type, i wonder if can i use the server side validation?

2- Can you give me an example of using "Error on upload holder", can I use it to manage the file in pdf format?

Submitted by romain.bioteau on Sat, 03/04/2023 - 15:17

I have updated the answer, Error on upload holder can be used to retrieve the server error response.

HTH
Romain

Notifications