Validating size of documents

1
0
-1

Hi.

I have a form and a upload widget working fine. When submited, it sets the file in a document defined in my process. I need to validate de size of this document. I try to create a grovy script validator but i just have a instance of org.bonitasoft.engine.bpm.document interface and it not have methods to get lenght. How can i validate the size of documents?

Thanks.

2 answers

1
0
-1

I think i resolve the problem.

1) Create a variable of type Document in my process (called documentFile) 2) Add a operation in my task and assign my Document to my variable 3) Create a Service Task to be called after my original task was submited 4) In this task, search by content bytes of my Document and do the validations

  1. import javax.activation.MimetypesFileTypeMap;
  2.  
  3. //here we can use the length of byte[] to validate the size of Document
  4. byte[] byteFile= apiAccessor.getProcessAPI().getDocumentContent(documentFile.getContentStorageId());
  5.  
  6.  
  7. //here we can validate the mimetype of file
  8. String mimeFile = URLConnection.guessContentTypeFromStream(is);
  9.  
  10. if( !mimeFile .contains("image/") && !mimeFile .contains("application/pdf")){
  11. return "Invalid file";
  12. }
  13.  
  14. return "";

1
0
-1

Hello, Unfortunally, you can't validate the size before the submit (so, in a validator). File is save in a temporary file on the server site, and you have no way (in Java or in Groovy) to access it. After the submit, you can access the file in the next step (or in the output connector).

Note the engine don't limit the upload size, but limit the document size to 15 mb.

Comments

Submitted by pedrovitorlima on Wed, 04/16/2014 - 15:22

Well... this is bad :( Maybe i can add a task after the form to validate de size of file and if dont pass i can clean the document and send to the upload task. But, how can i access a file after submit the upload? I have a Document as a variable in my process.

Thanks Pierre-yves!

Submitted by Pierre-yves Monnet on Thu, 04/17/2014 - 09:38

Maybe i can add a task after the form to validate de size of file and if dont pass i can clean the document and send to the upload task - ==> Exactly, that what I mean by "you can access the file in the next step". At this moment, the file uploaded is accessible in the Document, and you can do what you want.

That what you did if I look your last comment.

Notifications