Upload document to Alfresco via AlfrescoRestClient in Groovy not working...?

1
0
-1

Hello Everybody,

I have put a few documents in a list and these documents I want to upload to Alfresco.

This is the code I made:

  1. import org.bonitasoft.connectors.alfresco34.AlfrescoResponse;
  2. import org.bonitasoft.connectors.alfresco34.AlfrescoRestClient;
  3. import org.bonitasoft.engine.api.DocumentAPI;
  4. import org.bonitasoft.engine.bpm.document.Document;
  5. import org.bonitasoft.engine.bpm.document.DocumentDefinition;
  6. import org.bonitasoft.engine.bpm.document.impl.DocumentDefinitionImpl;
  7. import org.apache.abdera.*;
  8.  
  9. import java.util.logging.Logger;
  10.  
  11. import com.google.gson.Gson;
  12.  
  13. Logger logger= Logger.getLogger("org.bonitasoft");
  14. Gson gson = new Gson();
  15.  
  16.  
  17. logger.severe("*UPLOAD listWithImages: " + listWithImages);
  18.  
  19. try {
  20. def host = alfrescoHost;
  21. def port = alfrescoPort;
  22. def user = alfrescoUser;
  23. def pass = alfrescoPass;
  24.  
  25. AlfrescoRestClient alfresco = new AlfrescoRestClient(host, port, user, pass);
  26. logger.severe("*UPLOAD objAlfresco: " + gson.toJson(alfresco));
  27.  
  28. String fileName = "";
  29. String description = "";
  30. String mimeType = "";
  31. String destinationFolder = "";
  32.  
  33. for (file in listWithImages) {
  34. Document doc = apiAccessor.processAPI.getDocumentAtProcessInstantiation(processInstanceId, file["newAPImage"]);
  35. byte[] fileBytes = apiAccessor.processAPI.getDocumentContent(doc.contentStorageId)
  36.  
  37. //apiAccessor.processAPI.getDo
  38. logger.severe("*UPLOAD hasContent: " + doc.hasContent().toString());
  39. logger.severe("*UPLOAD contentFileName: " + doc.contentFileName);
  40. logger.severe("*UPLOAD contentStorageId: " + doc.contentStorageId);
  41.  
  42. //def fileLength = fileBytes;
  43. fileName = URLEncoder.encode(file["strAcceptancePointName"]);
  44. description = "null";
  45. mimeType = "image/jpeg";
  46. destinationFolder = URLEncoder.encode("/Startpagina's van gebruikers/Bonita");
  47.  
  48. AlfrescoResponse resp = alfresco.uploadFileFromDocument(doc, fileBytes, doc.contentFileName, description, mimeType, destinationFolder);
  49.  
  50. def statusInfo = [resp.getStackTrace(),
  51. resp.getResponseType(),
  52. resp.getStatusCode(),
  53. resp.getStatusText()];
  54. logger.servere(statusInfo);
  55.  
  56. }
  57. logger.severe("*UPLOAD ErrorMessage: " + e.getMessage());
  58. }

In the log I get the following line:

  1. INFO: uploadFileFromDocument documentName=newAPImage_0-cb5d87c4-1b97-4338-937b-bb1937fdd486 fileName=CabinetOverview.jpg description=null mimeType=image/jpeg destinationFolder=%2FStartpagina%27s+van+gebruikers%2FBonita

and nothing else....

What am I missing here? Via de Alfresco connector I can upload a document but with the above code the execution seems to get stuck.

Kind regards, Steven

No answers yet.
Notifications