Rest Api : Link a File to a Site

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

Rest Api : Link a File to a Site

Hi,

 

I m using Alfresco Community 5.2. I want to create link a file(this file is in another site) to site by using REST API. But I can not find any document about this issue.

 

How can I create link to site for folder or any document?

Thanks in advance..

10 Replies
afaust
Master

Re: Rest Api : Link a File to a Site

Depending on what kind of link you want to create (symlink- or hardlink-like, or even just a peer-reference) you would have to deal with either creating/managing a node or handling associations of a node. Depending on the kind of link you may either have to know the type / property / association to use, or even create your own custom content model if nothing of the existing fits your requirement.

Unfortunately you did not really specify what the kind of link should be, e.g. what its purpose is and how it should be presented to the end-user, so my comment is rather abstract and you will probably not find any documentation on such an abstract level.

mehe
Senior Member II

Re: Rest Api : Link a File to a Site

If you just want to create a filelink it should work with the "create node" rest endpoint (see alfresco-API-explorer, see Axels create link above)

Type should be an  app:filelink and in the properties you need a cm:destination set to the targets nodeRef (with workspace://SpacesStore). I think adding ".lnk" or ".url" as Extension in the nodename will force share to show an appropriate icon. 

But I never tried it myself....

hardik1512
Established Member II

Re: Rest Api : Link a File to a Site

How about below webscripts?

/alfresco/s/api/node/doclink/{store_type}/{store_id}/{id}
/alfresco/s/api/site/doclink/{site}/{container}/{path}
/alfresco/s/api/site/doclink/{site}/{container}

You can find more info at webscript home.

afaust
Master

Re: Rest Api : Link a File to a Site

You should not rely on those web scripts - they are marked with the lifecycle "internal" which means they are meant to be consumed by the Alfresco products and may change (without notice) between Alfresco versions. That is the reason that there exists a new v1 ReST API to get people off using these internal APIs.

hilal_aslan
Active Member II

Re: Rest Api : Link a File to a Site

I m clicking "copy to" on myfiles folder or any site folder. And after that, it is appear a button called "create link". By clicking this button, I can create link for this document to any place. But now, I want to make this process (create link) with rest api.

hilal_aslan
Active Member II

Re: Rest Api : Link a File to a Site

Ok but what about parameters ?

hilal_aslan
Active Member II

Re: Rest Api : Link a File to a Site

any help!

janv
Alfresco Employee

Re: Rest Api : Link a File to a Site

Martin and Alex are correct. You should be able to use the new V1 REST API to create a node of the given node type (app:filelink) and set the property (cm:destination). We also have a basic unit test for this specific scenario.

See also: 

[REPO-248] Support creation of (custom) node types that do not descend from cm:content or cm:folder ... 

Regards,

Jan


					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
hilal_aslan
Active Member II

Re: Rest Api : Link a File to a Site

Ok but what is Api URL ? my api url is "http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/43ad4f37-7bff-491e-b63... "  

and my parameters : 

{
"name": "Test file link",
"nodeType": "app:filelink",
"properties" : {
"cm:destination" : "b3ee89c4-bf02-44dc-a0e9-9ca6fdc9b97b"
}
}

but I get error "400 bad request"

{
"error": {
"errorKey": "Failed to change (specialise) node type - from {http://www.alfresco.org/model/content/1.0}folder to {http://www.alfresco.org/model/application/1.0}filelink",
"statusCode": 400,
"briefSummary": "06030125 Failed to change (specialise) node type - from {http://www.alfresco.org/model/content/1.0}folder to {http://www.alfresco.org/model/application/1.0}filelink",
"stackTrace": "For security reasons the stack trace is no longer displayed, but the property is kept for previous versions",
"descriptionURL": "https://api-explorer.alfresco.com"
}
}