As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
Hi, I'm using the acs-deployment 7.2.0 (the docker deployment) and I would like to upload a file using the REST APIs with Java HttpURLConnection, so by explicitly doing the POST (at the moment I cannot use the ReST API Java Wrapper Extension Point). From https://docs.alfresco.com/content-services/latest/develop/rest-api-guide/folders-files/#uploadfile I see the curl example, but I could not "translate" it in Java (I had no problem with the POST using the alfresco/api/-default-/public/authentication/versions/1/tickets call). I do not know how to deal with the various "-F" parameters and on how to pass the content of the file itself.
Has anyone use the direct REST APIs to upload a file in ACS? Could you please provide me a simple example on how to do it?
Thank you
Andrea
This may help:
https://hub.alfresco.com/t5/alfresco-content-services-blog/v1-rest-api-part-3-creating-nodes/ba-p/288503
angelborroy thank you for the response.
Following the link you provided, I was able to make it work with CloseableHttpClient + HttpPost + MultipartEntityBuilder classes. I'm still not able to make it work with the HttpURLConnection (I get a 400 response), but at least I know it can work with plain Java calls using the REST APIs.
The working code (so it could be useful for anyone who has the same issue) is:
CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost uploadFile = new HttpPost("http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-shared-/children"); uploadFile.addHeader("Authorization", bacisAutString); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); FileBody fileBody = new FileBody(new File(filePath)); builder.addPart("filedata", fileBody); HttpEntity multipart = builder.build(); uploadFile.setEntity(multipart); HttpResponse response = httpClient.execute(uploadFile);