cancel
Showing results for 
Search instead for 
Did you mean: 

Upload file along with aspect properties

groberts
Champ on-the-rise
Champ on-the-rise
I can upload files to Alfresco 3.4 using the web script

alfresco/service/api/upload

but now I have added an custom aspect to Alfresco,  is there any way to set properties from this aspect when a file is uploaded ?  Or even afterwards.

Hopefully I am missing something because I can't see how to set bespoke properties on file uploaded via a web script.

Thanks,

Guy.
8 REPLIES 8

marcoq82
Champ in-the-making
Champ in-the-making
You can:

1) Set a business rule which applies the aspect to all uploaded file (of a certain space). Each time you upload a file, Alfresco will apply the aspect for you and then you modify aspect properties using Alfresco Explorer

2) write a new web script which:
               - uploads the file
               - applies the aspect to the file
               - modify the properties of the aspect (e.g. taking values from a form)

groberts
Champ on-the-rise
Champ on-the-rise
Good,  I'll write a new web script that adds the aspect and sets the properties.

I don't know how many other people are trying to use the REST API without Share,  but applying an aspect to an uploaded file must be a common requirement.

Thanks,

Guy.

kevinr
Star Contributor
Star Contributor
Yes a rule is a good way to approach this. Customising the webscript can of course be done, but it currently involves overriding the entire controller script for upload.post.js. We are looking at this area (and many others!) to improve extensibility in Share/REST APIs for the next major release.

Cheers,

Kev

groberts
Champ on-the-rise
Champ on-the-rise
Kevin, 

Thanks for your reply,

I understand you cautioning against using a Web Script to set aspect properties after file upload,  but I can't use the Alfresco Java Server Faces client because our application only uses Alfresco for part of its functionality.

Guy.

groberts
Champ on-the-rise
Champ on-the-rise
The Javascript webscript

webscripts/org/alfresco/repository/upload/upload.post.js 

checks for a list of aspect names and adds them if supplied.  So I can duplicate the script, rename it and use that.   So full marks to who ever wrote the script int he first place.

        
         // Additional aspects?
         if (aspects.length > 0)
         {
            for (i = 0; i < aspects.length; i++)
            {
               newFile.addAspect(aspects[i]);
               newFile.save();
            }
         }

kevinr
Star Contributor
Star Contributor
Good - i'll pass along your comments Smiley Wink

sanket
Champ on-the-rise
Champ on-the-rise
newFile.addAspect  -> This adds the aspect.

1) What I need to do to set the value of that new aspect ?

2) And how can I add my custom aspect ?
    Do I need to change the contentModel ? I tried it but it gives errors when I restart the server.

Thanks in advance,
Sanket Mehta.

sunitha
Champ in-the-making
Champ in-the-making
hi..
reference with your post…can u upload a file along with aspect properties????
for this did you changed the content model..?
can you please explain me about your code..
actually i have the requirement in this topic..
please provide me the source code..
thanking you..