Upload file using webscript

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2009 04:25 AM
Hello,
I'm building a simple cm server, and I want my users to be able to upload content to a certain space (almost always the same one), and to be able to apply a tag to it (categorize the content). I tried to do it using the upload webscript provided in the webscripts samples (http://wiki.alfresco.com/wiki/Web_Scripts_Examples#File_Upload), but I got stuck pretty fast.
Can I do it with web scripts? how?
If not, where can I find information about doing it with JAVA servlets?
I should mention that I'm very new to Alfresco, but it seemed nice and easy..
Thanks,
Shai
I'm building a simple cm server, and I want my users to be able to upload content to a certain space (almost always the same one), and to be able to apply a tag to it (categorize the content). I tried to do it using the upload webscript provided in the webscripts samples (http://wiki.alfresco.com/wiki/Web_Scripts_Examples#File_Upload), but I got stuck pretty fast.
Can I do it with web scripts? how?
If not, where can I find information about doing it with JAVA servlets?
I should mention that I'm very new to Alfresco, but it seemed nice and easy..
Thanks,
Shai
Labels:
- Labels:
-
Archive
4 REPLIES 4

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2009 03:45 AM
Hi,
You can definitely do that in webscripts. Where are you getting stuck?
You can definitely do that in webscripts. Where are you getting stuck?

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2009 03:50 AM
Hi,
I can't figure out how to create the new content in a specified space other than 'company home'…
Shai
I can't figure out how to create the new content in a specified space other than 'company home'…
Shai

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2009 04:03 AM
Hi,
If the space is always the same one, then just get its node reference (you can get that in the Explorer UI : more actions > view details, then copy the Alfresco Node Reference link), which should look like: workspace://SpacesStore/8469e812-6383-42f6-9d89-872810d0e547
Then in the script, at the bottom you see:
you need to change this to something like:
Rather than using a hardwritten node ref, you can also use:
(note that this is less robust, if someone decides to rename your folder you're stuck).
As for the tagging, you can use the addTag method on ScriptNode; so in the script add in something like:
Hope that helps,
Sylvain.
PS you may be interested in reading the documentation: http://wiki.alfresco.com/wiki/JavaScript_API
If the space is always the same one, then just get its node reference (you can get that in the Explorer UI : more actions > view details, then copy the Alfresco Node Reference link), which should look like: workspace://SpacesStore/8469e812-6383-42f6-9d89-872810d0e547
Then in the script, at the bottom you see:
// create document in company home for uploaded file upload = companyhome.createFile("upload" + companyhome.children.length + "_" + filename) ; upload.properties.content.write(content); upload.properties.encoding = "UTF-8"; upload.properties.title = title; upload.properties.description = description; upload.save()
you need to change this to something like:
var folder = search.findNode("workspace://SpacesStore/8469e812-6383-42f6-9d89-872810d0e547"); // create document in folder for uploaded file upload = folder.createFile("upload" + folder.children.length + "_" + filename) ; upload.properties.content.write(content); upload.properties.encoding = "UTF-8"; upload.properties.title = title; upload.properties.description = description; upload.save()
Rather than using a hardwritten node ref, you can also use:
var folder = companyhome.childByNamePath("Data Dictionary/Wherever/You/Need");
(note that this is less robust, if someone decides to rename your folder you're stuck).
As for the tagging, you can use the addTag method on ScriptNode; so in the script add in something like:
upload.addTag("my_wonderful_new_tag");
Hope that helps,
Sylvain.
PS you may be interested in reading the documentation: http://wiki.alfresco.com/wiki/JavaScript_API

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2009 04:36 AM
Thanks a lot! It really helped, just as I was beginning to get too frustrated..
