cancel
Showing results for 
Search instead for 
Did you mean: 

Create folder / upload files with cURL POST and special characters

sistemi
Confirmed Champ
Confirmed Champ

Hi, I am trying to create a folder on Alfresco 6.2 using cURL and POST: everything works normally, except if the folder that I am trying to create contains some special characters (e.g. è ì à ù) in the name: these characters are not correctly interpreted and the folder is created with wrong name:

curl -X POST http://localhost/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Sites/share/documentLibrary/files -H 'authorization: Basic XXXXXXXXXXXXX' -H 'content-type: multipart/form-data' -F cmisaction=createFolder -F 'propertyId[0]=cmis:objectTypeId' -F 'propertyValue[0]=cmis:folder' -F 'propertyId[1]=cmis:name' -F "propertyValue[1]=L'AGO...rùèàì" -F succinct=true

The resulting folder name in Alfresco is: 

"L'AGO...rùèàì"

 Is there a way to have these characters correctly interpreted?

6 REPLIES 6

sufo
Star Contributor
Star Contributor

Try to specify utf-8 charset in the content-type header:

-H 'content-type: multipart/form-data; charset="utf-8"'

sistemi
Confirmed Champ
Confirmed Champ

Hi, thanks for your answer, I tried but the resulting folder is the same. 

Here is my request from command line:

root@test:# curl -X POST http://localhost/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Sites/shareA/documentLibrary/fileTest -H 'authorization: Basic XXXXXXXXXXXXXXXXXXXXX' -H 'content-type: multipart/form-data; charset="utf-8"' -F cmisaction=createFolder -F 'propertyId[0]=cmis:objectTypeId' -F 'propertyValue[0]=cmis:folder' -F 'propertyId[1]=cmis:name' -F "propertyValue[1]=L'AGO...ràaèeiìoòuù" -F succinct=true

And here is Alfresco Answer, folder name contains wrong characters:

{"succinctProperties":{"cmis:objectId":"cba5f4ca-f6aa-4d00-b73b-755f0079ed66","alfcmis:nodeRef":"workspace:\/\/SpacesStore\/cba5f4ca-f6aa-4d00-b73b-755f0079ed66","cmis:path":"\/Sites\/shareA\/documentLibrary\/fileTest\/L'AGO...ràaèeiìoòuù","cmis:allowedChildObjectTypeIds":null,"cmis:lastModifiedBy":"admin","cmis:secondaryObjectTypeIds":["P:sys:localized"],"cmis:objectTypeId":"cmis:folder","cmis:description":null,"cmis:createdBy":"admin","cmis:baseTypeId":"cmis:folder","cmis:parentId":"532a7175-0851-45db-843a-b2bf111f0b75","cmis:creationDate":1615815273567,"cmis:changeToken":null,"cmis:name":"L'AGO...ràaèeiìoòuù","cmis:lastModificationDate":1615815273567},"propertiesExtension":{"aspects":{"appliedAspects":"P:sys:localized"}}}

And browsing folder from Alfresco share confirms that the name is wrong:image

sufo
Star Contributor
Star Contributor

What is the output of these two commands (possibly your console is not using utf-8)?

locale
locale charmap

sistemi
Confirmed Champ
Confirmed Champ

Hi, here is the output of the two commands:

root@test:~# locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=


root@test:~# locale charmap
UTF-8

sufo
Star Contributor
Star Contributor

I found out that either server or curl is not working properly. Only way for you to get it working is to prepare form data yourself in the file and send it with curl. We have it working in our implementation (not curl), because we are sending charset with each field:

-----------------------------1783cd3da56
Content-Disposition: form-data; name="cmisaction"
Content-Type: text/plain; charset=utf-8

createFolder
-----------------------------1783cd3da56
Content-Disposition: form-data; name="succinct"
Content-Type: text/plain; charset=utf-8

true
-----------------------------1783cd3da56
Content-Disposition: form-data; name="propertyId[0]"
Content-Type: text/plain; charset=utf-8

cmis:objectTypeId
-----------------------------1783cd3da56
Content-Disposition: form-data; name="propertyValue[0]"
Content-Type: text/plain; charset=utf-8

cmis:folder
-----------------------------1783cd3da56
Content-Disposition: form-data; name="propertyId[1]"
Content-Type: text/plain; charset=utf-8

cmis:name
-----------------------------1783cd3da56
Content-Disposition: form-data; name="propertyValue[1]"
Content-Type: text/plain; charset=utf-8

L'AGO...ràaèeiìoòuù
-----------------------------1783cd3da56--

curl sends it like this:

------------------------------ece9f7859ab7
Content-Disposition: form-data; name="cmisaction"

createFolder
------------------------------ece9f7859ab7

You can save first code block to a file test.txt and then you have to convert it to file with lines ending with CRLF (Windows style) using:

perl -pe 's/\r?\n/\r\n/' test.txt > test-win.txt

And then send it like this:

curl -X POST http://localhost/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Sites/shareA/documentLibrary/fileTest -H 'authorization: Basic XXXXXXXXXXXXXXXXXXXXX' -H "Content-Type: multipart/form-data; boundary=---------------------------1783cd3da56" --data-binary @test-win.txt

sistemi
Confirmed Champ
Confirmed Champ

Hi, thanks @sufo for your suggestion, it worked very well with folder creation! 

Can it be applied also to file upload? I tried to modify your suggestion by adding a "file" section, but the result is a file with correct name (including accented characters) but of 0 kb size.

Here is a CURL post that correctly uploads the file but does not encode correctly filenames:

curl -X POST 'http://localhost/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Sites/share/documentLibrary/files' -H 'authorization: Basic XXXXXXXXXXXXX'  -H 'content-type: multipart/form-data' -F cmisaction=createDocument -F 'propertyId[0]=cmis:objectTypeId' -F 'propertyValue[0]=cmis:document' -F 'propertyId[1]=cmis:name' -F "propertyValue[1]=fileàèòìù.odt" -F "file=@/home/user/test.odt" -F succinct=true