Add custom metadata with new file upload

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member

Add custom metadata with new file upload

Jump to solution

Hello,
I'm using PortCmis with AtomPub 1.1 in .Net Core and I'm trying to upload a file to Alfresco. I'm trying to set custom metadata., but I'm getting this error: Type classification is unknown!
Here is my code:


parameters[SessionParameter.User] = "myuser";
parameters[SessionParameter.Password] = "mypassword";
parameters[SessionParameter.AtomPubUrl] = "http://my-address-where-is-alfresco/alfresco/api/-default-/public/cmis/versions/1.1/atom";
parameters[SessionParameter.BindingType] = BindingType.AtomPub;
parameters[SessionParameter.PreemptivAuthentication] = "True";

IDictionary<string, object> properties = new Dictionary<string, object>();
properties[PropertyIds.Name] = fileName;

IList<string> secondaryTypes = new List<string>();
secondaryTypes.Add("custom:classification");

properties[PropertyIds.SecondaryObjectTypeIds] = secondaryTypes;
properties["classification"] = "test classification";

After this I'm creating contentStream in a proper way and using it to create document.

var newDoc = folder.CreateDocument(properties, contentStream, VersioningState.None);

Does anyone has same error "Type classification is unknown!" ???


3 Solutions

Accepted Solutions
Highlighted
Alfresco Employee

Re: Add custom metadata with new file upload

Jump to solution

When adding an aspect (secondaryType), you need to add the prefix "P:" to your aspect name.

secondaryTypes.Add("P:custom:classification");

You need also to be sure that the model definition has been deployed in Alfresco Repository.

Software Engineer in Alfresco Search Team.

View solution in original post

Highlighted
Intermediate II

Re: Add custom metadata with new file upload

Jump to solution

Alfresco model is just an xml ,so you can create the xml model file in c# and upload the xml file into Company Home/Data Dictionary/Models using cmis api.

View solution in original post

Highlighted
Intermediate II

Re: Add custom metadata with new file upload

Jump to solution

Yes ,upload your xml to Repository/Models. and you also need to set cmisSmiley SurprisedbjectTypeId to D:cm:dictionaryModel,and cm:modelActive property to true. Then you can use your types and aspects defined in your model.

View solution in original post

8 Replies
Highlighted
Alfresco Employee

Re: Add custom metadata with new file upload

Jump to solution

When adding an aspect (secondaryType), you need to add the prefix "P:" to your aspect name.

secondaryTypes.Add("P:custom:classification");

You need also to be sure that the model definition has been deployed in Alfresco Repository.

Software Engineer in Alfresco Search Team.

View solution in original post

Highlighted
Active Member

Re: Add custom metadata with new file upload

Jump to solution

Thank you! Do you know if I can define and deploy model from C# code or that can be done only in Alfresco repository by Admin?

Highlighted
Intermediate II

Re: Add custom metadata with new file upload

Jump to solution

Alfresco model is just an xml ,so you can create the xml model file in c# and upload the xml file into Company Home/Data Dictionary/Models using cmis api.

View solution in original post

Highlighted
Active Member

Re: Add custom metadata with new file upload

Jump to solution

Hi kaynezhang,
Is there any tutorial how to do it? I've created some xml model file, but I'm not sure where to upload it either with C# or with drag and drop.

Highlighted
Community Manager
Community Manager

Re: Add custom metadata with new file upload

Jump to solution

Hi @goranche89,

There are several tutorials for creating models in Alfresco. A very recent one by @Jendert , Creating a simple Contract Management Solution, is a very good introduction.   There are also Jeff Pott's Alfresco Developer Tutorials.

With regard to using the Alfresco ReST API, there's Gavin Cornwell's blog series. & also @Jendert API tutorial (still a work in progress).

HTH

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!
Highlighted
Active Member

Re: Add custom metadata with new file upload

Jump to solution

Hi,
I've uploaded an xml to Repository/Models. I like that approach to upload xml and than use it as a custom model. But I don't know is that enough or I must do something else? I see that in Admin Tools there is no my custom model, and that other approach is to simply create it with wizard., but I don't want that.
So to recapitulate, I've uploaded my xml model to Models and I can see that document as document in xml format. What is next step to be able to use that custom model for uploading files with aspects defined in that model?

Highlighted
Intermediate II

Re: Add custom metadata with new file upload

Jump to solution

Yes ,upload your xml to Repository/Models. and you also need to set cmisSmiley SurprisedbjectTypeId to D:cm:dictionaryModel,and cm:modelActive property to true. Then you can use your types and aspects defined in your model.

View solution in original post

Highlighted
Active Member

Re: Add custom metadata with new file upload

Jump to solution

Thank you all! It works! Smiley Happy