AnsweredAssumed Answered

Failed to set the mime type for uploading file

Question asked by srinivasan on Jul 24, 2006
Latest reply on Jul 24, 2006 by davidc
Hi Developers,

I am trying to import the msword file to alfresco repositry thru plain java code.

MY code is given below:

public void createContentWithSpace(NodeRef nodeRef, String contentName,
ServiceRegistry serviceRegistry) {
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
contentProps.put(ContentModel.PROP_NAME, contentName);

// create content node
NodeService nodeService = serviceRegistry.getNodeService();
ChildAssociationRef association = nodeService.createNode(nodeRef,
ContentModel.ASSOC_CONTAINS, QName.createQName(
NamespaceService.CONTENT_MODEL_PREFIX, contentName),
ContentModel.TYPE_CONTENT, contentProps);
NodeRef content = association.getChildRef();

// add titled aspect (for Web Client display)
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>();
titledProps.put(ContentModel.PROP_TITLE, contentName);
titledProps.put(ContentModel.PROP_DESCRIPTION, contentName);
nodeService.addAspect(content, ContentModel.ASPECT_TITLED, titledProps);


//write content to the file
File file = new File("C:/Temp/Test.doc");
ContentService contentService = serviceRegistry.getContentService();
ContentWriter writer = contentService.getWriter(content,
ContentModel.PROP_CONTENT, true);

String mimeType ="application/msword"; writer.setMimetype(mimeType);
writer.putContent(file);

}

for msword document the mimetype is "application/msword"

writer.putContent(file);

in the above line i just the passed the file object.

This code works perfectly. When i logged into webclient, i am able to see the imported document. The problem is when i clicking the imported msword document, a 'File Download' popup is enable and it provide options like 'open', 'save' and so on and it opened when i click the open
button.

My question :

Why I am getting the 'File Download' popup?

When I upload the existing file through 'add content' link in Web Client, it uploading perfectly and also i can able to see the related icon for eg. for pdf file i can see the pdf icon and for msword document i can see the msword icon. When i click the document i didn't get any popup.

But when i upload through my java code, i am not able to see the related file icon like msword, pdf and so on. Do you know why it is?


Is there anything wrong in my code while setting the mimetype or do i need to set the encoding. If so how can i achive this?

Outcomes