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!" ???
Solved! Go 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.
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.
Yes ,upload your xml to Repository/Models. and you also need to set cmisbjectTypeId to D:cm:dictionaryModel,and cm:modelActive property to true. Then you can use your types and aspects defined in your model.
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.
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?
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.
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.
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
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?
Yes ,upload your xml to Repository/Models. and you also need to set cmisbjectTypeId to D:cm:dictionaryModel,and cm:modelActive property to true. Then you can use your types and aspects defined in your model.
Thank you all! It works!
This is the solution that worked for me. I also had the same question and issue - Using REST, to upload file alongwith metadata here:
I was trying to get it done using Spring RestTemplate but couldne make it. So I reached Alfresco support. And those guyz are awesome. They gave me the solution that worked flawlessly.
Here is the solution:
private static void postFileAndMetadataToAlfresco() throws IOException {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(POST_URL);
UsernamePasswordCredentials creds = new UsernamePasswordCredentials ("admin","adminpswd");
httpPost.addHeader (new BasicScheme().authenticate(creds,httpPost, null));
File payload = new File ("/path/to/my/file.pdf");
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); // Entity builder
builder.addPart("filedata", new FileBody(payload)); // this is where I was struggling
builder.addTextBody ("name", "thenamegoeshere");
builder.addTextBody ("foo", "foo");
builder.addTextBody ("bar", "bar");
builder.addTextBody ("description", "descriptiongoeshere");
builder.addTextBody ("overwrite", "true");
HttpEntity entity = builder.build();
httpPost.setHeader("Accept","application/json");
httpPost.setEntity(entity);
CloseableHttpResponse response = client.execute(httpPost); // Post the request and get response
System.out.println(response.toString()); // Response print to console
client.close(); // close the client
}
Hoping it might help someone like me.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.