Add document (Rest API)
Hello,
I' m trying to upload files with bonita rest API and I had two problems:
- To test rest Api, in chrome I make login in bonita portal, and created a case. In the same browser i open a new tab and in postman extension I build a request like this
url = http://localhost:8080/bonita/API/bpm/caseDocument:
data = {"caseId":"29","file":"C:\flexitex2.jpg","name":"flexitex2","description":"draft"} where my case id was = 29.
The server send back that response
{ "id": "3", "creationDate": "2015-01-14 14:42:16.237", "author": "25", "index": "-1", "contentMimetype": "", "caseId": "29", "description": "draft", "name": "flexitex2", "fileName": "", "isInternal": "true", "submittedBy": "25", "url": "documentDownload?fileName=null&contentStorageId=3", "contentStorageId": "3", "version": "1" }
The attr content type and fileName is empty. What I am doing wrong here?
- In widget html in one form I have this script
$.post( "http://localhost:8080/bonita/API/bpm/caseDocument", JSON.stringify( {"caseId": caseId, "file": "C:\flexitex1.PNG", "name": "flexitex1", "description": "draft"}), });
this scripts runs when i click in one specific button. The server send back this response was:
exception: "class java.lang.NullPointerException" message: "" stacktrace: ["org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:212)",…] 0: "org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:212)" 1: "org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:198)" 2: "org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:188)" 3: "org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:168)" 4: "org.bonitasoft.web.rest.server.framework.APIServletCall.getJSonStreamAsItem(APIServletCall.java:129)"
What I am doing wrong in this script?
Can anyone help me with this call?
Thanks in advance and sorry for my english.
I think it should be possible to achieve your use case by doing to separated call to the API:
- First call will create the process instance. See "Create a case" on this documentation page: http://documentation.bonitasoft.com/bpm-api#case
- Second call will add the document to the process instance (document of the document will be stored by Bonita Engine). See "Add a document to a case" on this documentation page: http://documentation.bonitasoft.com/bpm-api#casedocument. Note that file need to be located on the server. If file is on end user computer it needs first to be uploaded to the server. To upload the file to the server you can use TenantUploadFileServlet
Comments
Thanks for your answers,
I resolved the problem. My intention was develop in bonita form a user interface to upload multiple files. So, I created two types of interfaces (for test). In first interface it is possible to user attach one file for task, and interface show all filles of the process. I do this because, if we submitted a task with a file and the process return to this task again and user need to attach another file without override the first file, he can´t. In second interface the user can add multiple file to a task but for that, he have to put the full file path to upload the file in one textField. It works, but i have to do better, I am not satisfied for the second solution.
Hello,
FYI, uploading multiple files within a single form can be achieved using the "Dynamic Web forms designer" feature that is part of the Subscription editions: http://www.bonitasoft.com/how-we-do-it/compare-editions
Cheers,
Hola Jarg Estoy en un problema similar de adjuntar varios archivos podrias ayudarme??