cancel
Showing results for 
Search instead for 
Did you mean: 

uploading a file

hatonis
Champ in-the-making
Champ in-the-making
Hello,

I wanted to know how to upload a file with open CMIS (using the alfresco openCMIS extension).
I know how to create a simple content but don't know how to simply upload a pdf file or something else.
I looked for tutorials and searched on the forum but didn't find anything.

Thanks.
3 REPLIES 3

glaenen
Champ in-the-making
Champ in-the-making
You could try like this:

ContentStream contentStream = null;
try {
   contentStream = new ContentStreamImpl("test.jpg", null, "image/jpeg", new FileInputStream("c:/test.jpg"));
} catch (FileNotFoundException e) {
   e.printStackTrace();
}
   
if (contentStream != null) {
   Map<String, Object> properties = new HashMap<String, Object>();
   properties.put(PropertyIds.NAME, contentStream.getFileName());
   properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
   Document doc = session.getRootFolder().createDocument(properties, contentStream , null);
}

Regards,

Glenn

hatonis
Champ in-the-making
Champ in-the-making
Hello,

Thanks for the reply. It works but when I try to update the document, i have a CmisRuntimeException at the following line :
Document doc = session.getRootFolder().createDocument(properties, contentStream , null );
And the document is not updated.

I tried to find a solution so that i can update the document but i didn't find it. I tried to modify the VersioningState but it didn't work.
Could you please tell me how to update the document?

Thanks.

fmui
Champ in-the-making
Champ in-the-making
You can't update a document with createDocument.

If you want to update the properties, use updateProperties(). If you want to update the content, use setContentStream(). If you want to create a new document version, check out the document with checkOut(), update the private working copy (its object id is returned by checkOut()) and check the private working copy in with checkIn().

- Florian