<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Uploading file using the REST API with HttpURLConnection in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/uploading-file-using-the-rest-api-with-httpurlconnection/m-p/126197#M34375</link>
    <description>&lt;P&gt;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 &lt;A href="https://docs.alfresco.com/content-services/latest/develop/rest-api-guide/folders-files/#uploadfile" target="_blank" rel="noopener nofollow noreferrer"&gt;https://docs.alfresco.com/content-services/latest/develop/rest-api-guide/folders-files/#uploadfile&lt;/A&gt; 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.&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Andrea&lt;/P&gt;</description>
    <pubDate>Wed, 07 Dec 2022 15:58:45 GMT</pubDate>
    <dc:creator>aturbati</dc:creator>
    <dc:date>2022-12-07T15:58:45Z</dc:date>
    <item>
      <title>Uploading file using the REST API with HttpURLConnection</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/uploading-file-using-the-rest-api-with-httpurlconnection/m-p/126197#M34375</link>
      <description>&lt;P&gt;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 &lt;A href="https://docs.alfresco.com/content-services/latest/develop/rest-api-guide/folders-files/#uploadfile" target="_blank" rel="noopener nofollow noreferrer"&gt;https://docs.alfresco.com/content-services/latest/develop/rest-api-guide/folders-files/#uploadfile&lt;/A&gt; 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.&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Andrea&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 15:58:45 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/uploading-file-using-the-rest-api-with-httpurlconnection/m-p/126197#M34375</guid>
      <dc:creator>aturbati</dc:creator>
      <dc:date>2022-12-07T15:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: Uploading file using the REST API with HttpURLConnection</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/uploading-file-using-the-rest-api-with-httpurlconnection/m-p/126198#M34376</link>
      <description>&lt;P&gt;This may help:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://hub.alfresco.com/t5/alfresco-content-services-blog/v1-rest-api-part-3-creating-nodes/ba-p/288503" target="_blank" rel="nofollow noopener noreferrer"&gt;https://hub.alfresco.com/t5/alfresco-content-services-blog/v1-rest-api-part-3-creating-nodes/ba-p/288503&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2022 09:27:01 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/uploading-file-using-the-rest-api-with-httpurlconnection/m-p/126198#M34376</guid>
      <dc:creator>angelborroy</dc:creator>
      <dc:date>2022-12-12T09:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Uploading file using the REST API with HttpURLConnection</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/uploading-file-using-the-rest-api-with-httpurlconnection/m-p/126199#M34377</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;A class="" href="https://hub.alfresco.com/t5/user/viewprofilepage/user-id/5487" target="_self" rel="nofollow noopener noreferrer"&gt;&lt;SPAN class=""&gt;angelborroy&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt; thank you for the response.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;The working code (so it could be useful for anyone who has the same issue) is:&lt;/P&gt;&lt;PRE&gt;CloseableHttpClient httpClient = HttpClients.&lt;SPAN&gt;createDefault&lt;/SPAN&gt;()&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;HttpPost uploadFile = &lt;SPAN&gt;new &lt;/SPAN&gt;HttpPost(&lt;SPAN&gt;"http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-shared-/children"&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;uploadFile.addHeader(&lt;SPAN&gt;"Authorization"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;bacisAutString)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;MultipartEntityBuilder builder = MultipartEntityBuilder.&lt;SPAN&gt;create&lt;/SPAN&gt;()&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;FileBody fileBody = &lt;SPAN&gt;new &lt;/SPAN&gt;FileBody(&lt;SPAN&gt;new &lt;/SPAN&gt;File(&lt;SPAN&gt;filePath&lt;/SPAN&gt;))&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;builder.addPart(&lt;SPAN&gt;"filedata"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;fileBody)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;HttpEntity multipart = builder.build()&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;uploadFile.setEntity(multipart)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;HttpResponse response = httpClient.execute(uploadFile)&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Dec 2022 11:03:36 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/uploading-file-using-the-rest-api-with-httpurlconnection/m-p/126199#M34377</guid>
      <dc:creator>aturbati</dc:creator>
      <dc:date>2022-12-12T11:03:36Z</dc:date>
    </item>
  </channel>
</rss>

