08-25-2020 09:44 AM
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!" ???
08-25-2020 10:58 AM
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.
08-26-2020 03:44 AM
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.
08-27-2020 12:05 AM
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.
08-25-2020 10:58 AM
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.
08-26-2020 03:04 AM
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?
08-26-2020 03:44 AM
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.
08-26-2020 06:00 AM
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.
08-26-2020 06:38 AM
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
08-26-2020 07:13 AM
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?
08-27-2020 12:05 AM
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.
08-27-2020 05:31 AM
Thank you all! It works!
12-07-2020 02:33 PM
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.
Explore our Alfresco products with the links below. Use labels to filter content by product module.