how to only accept ".pdf" format for file upload in bonitasoft ?
1 answer
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>
<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
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?
I have updated the answer,
Error on upload holder
can be used to retrieve the server error response.HTH
Romain