cancel
Showing results for 
Search instead for 
Did you mean: 

API JS Problem managing content with accents and other symb.

madcaddie
Champ in-the-making
Champ in-the-making
Hi everyone!!!

Actually I’m having some problems with the JS API (in conjuntion with accented vowels and other special chars) when I’m reading the content of a .txt file.

My code opens a file that is placed in an Alfresco Space, like:
var file = companyhome.childByNamePath(“NAME OF THE TXT FILE”);

Then I obtain the content as follow:
var content = file.content;

And finally I assign this content as the value of a property of other content that I’ve in the repository, more or less like:
var doc = companyhome.childByNamePath(“NAME OF THE DOC FILE”);
doc.properties[“NAME PROPERTY”] =content;
doc.save();


The problem is that the chars as ‘á’, ‘à’, ‘é’, ’è’,… Are loaded as ‘?’ chars (the non special chars are displayed correctly).
On the other hand if you edit directly the property (from the properties sheet), you can put these special chars with no problem.

Any idea?

Thx.
Xavi
1 REPLY 1

madcaddie
Champ in-the-making
Champ in-the-making
Finally I’ve found a solution. The problem is related with the encoding of the file: if you update a plain txt to the system via CIFS (like I was doing), it takes as default the encoding UTF-8.

Then if you want to process it with symbols like accents and other special chars, the best that you can do is encode the file as “windows-1252” before processing the file.

If you add this modification to the previous code, it will look as:

var file = companyhome.childByNamePath(“NAME OF THE TXT FILE”);

file.properties.content.encoding = "windows-1252";

var content = file.content;
var doc = companyhome.childByNamePath(“NAME OF THE DOC FILE”);
doc.properties[“NAME PROPERTY”] =content;
doc.save();


See ya,
Xavi