cancel
Showing results for 
Search instead for 
Did you mean: 

How to assign a mimetype to document being created using REST API? (Alfresco 5.2)

mikeitexpert
Champ on-the-rise
Champ on-the-rise

hi,

I am wondering if there is anyway we can set/assign the content-mime type of a document being created using REST API.

I use the below this rest api  and I need to be able to set mimetype directly when the document is being created. 

Is that possible?

I did a few try and errors it seems that mimetype is determined based on the extension given to the name property passed to the api.

So if I for example use the below as the json post parameter, the mimetype becomes application/pdf but 

{
"name": "filename.pdf",
"nodeType": "string",

}

if use the below, the mimetype becomes applicaiton/image. 

{
"name": "filename.png",
"nodeType": "string",

}

Please advise if that can be set using REST API.

Thank you,

2 REPLIES 2

angelborroy
Community Manager Community Manager
Community Manager

You cannot set mime type when uploading, as it's autodetected. 

If you find any case where this detection process fails, you can modify mime type after uploading the content.

Hyland Developer Evangelist

Can you give a example for this ?

I have tried this:

FormData data = new FormData();
data.addFieldData("prop_mimetype", mimetype, true); Item itemMimetype = new Item("node", nodeRef.toString()); NodeRef nodeRefFoundedUpdated = (NodeRef)formService.saveForm(itemMimetype, data);

and this:

ContentWriter contentWriter = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
if(contentWriter != null) {
	contentWriter.setMimetype(mimetype);
}

but is not working is still a "application/octet-stream" value on alfresco share