cancel
Showing results for 
Search instead for 
Did you mean: 

Content mimetype property not a String

jordiv
Champ on-the-rise
Champ on-the-rise
Hi,

Inside an Alfresco webscript, given a node, I get its mime type as follows:
var mimeType = nodeVar.mimetype;
// This is also valid:
// var mimeType = nodeVar.properties.content.mimetype;

I get it succesfully, but the type of mimeType variable is object instead of String (as it should be according to the wiki). This can be checked by doing:
typeof nodeVar.mimetype;
I can change it to String by doing something like:
var mimeType = "" + nodeVar.mimetype;
But I would like to know if this is a bug or I'm doing something wrong.

Thanks,
Jordi.
4 REPLIES 4

loftux
Star Contributor
Star Contributor
The returned value is a java string (and not javascript string), typeof probably returns this as object.
Try something like
var mimeType = new String(nodeVar.mimetype);
and you will get a proper javascript string object. This applies to many alfresco javascript methods/properties, where for example equality operator === doesn't do what you would expect because they are different kind if string objects.

jordiv
Champ on-the-rise
Champ on-the-rise
Thanks for your reply Loftux.

It's odd, because I've tried using:

var mimeType = new String(nodeVar.mimetype);
var mimeType = nodeVar.mimetype.toString();
And none seems to work, the typeof mimeType keeps being object. The only way it works for me is adding an empty string as described in the first post.

Cheers,
Jordi.

loftux
Star Contributor
Star Contributor
What if you try nodeVar.properties.content.mimetype?
I checked the alfresco source, and the nodeVar.mimetype does return a string, so I'm not sure why the "new String()" does not work.

jordiv
Champ on-the-rise
Champ on-the-rise
I've also tried it and the result is the same.

I've done this tests in the JavaScript Console (doing it inside the webscript has the same effect):

var nodeVar = companyhome.childByNamePath("Sites/TestSite/documentLibrary/test/test.txt");
var mimeType;
mimeType = nodeVar.mimetype; print(typeof mimeType); // object
mimeType = nodeVar.mimetype.toString(); print(typeof mimeType); // object
mimeType = new String(nodeVar.mimetype); print(typeof mimeType); // object
mimeType = nodeVar.properties.content.mimetype; print(typeof mimeType); // object
mimeType = nodeVar.properties.content.mimetype.toString(); print(typeof mimeType); // object
mimeType = new String(nodeVar.properties.content.mimetype); print(typeof mimeType); // object
mimeType = "" + nodeVar.mimetype; print(typeof mimeType); // string
mimeType = "" + nodeVar.properties.content.mimetype; print(typeof mimeType); // string