cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco 2.1 - web scripts - file upload

lorty
Champ in-the-making
Champ in-the-making
Hi all,
I am trying to use Alfresco as a document storage engine for a Ruby on Rails app.
Reading the Alfresco Blog I learned the best way to accomplish this is to use the new web scripts feature.
I wrote a simple webscript to create a file, but  I have 2 questions:

1) how do I actually upload the file content from a form? As soon as I use a multipart/form-data form, I am not able anymore to retrieve "args" from the webscript. Am I missing somethig obvious here?

2) how is authentication performed from webscripts? How can I authenticate from an external (Rails) app?

I also tried to upload a file from my Rails app using the standard web services, I was able to authenticate and query the repository (using the ruby toolkit), but I'm stuck at creating new content (CMLCreate??), I only found examples in .NET and Java.

Any help would be great!
Thanks in advance,

Lorenzo Musizza
1000 ASA
8 REPLIES 8

davidc
Star Contributor
Star Contributor
1) how do I actually upload the file content from a form? As soon as I use a multipart/form-data form, I am not able anymore to retrieve "args" from the webscript. Am I missing somethig obvious here?

Support for multipart/form-data is not there yet.  Also, we don't have an upload web script as we do a download web script.  The only escape route at this time, is to develop a java backing-bean to a web script, but that's hard work.

This is obviously a hole, and it's something I hope to fill by 2.1 final.

2) how is authentication performed from webscripts? How can I authenticate from an external (Rails) app?

Authentication mechanisms may be plugged-in, but by default, Basic HTTP authentication is used.

santigt
Champ in-the-making
Champ in-the-making
The best Idea i have, for uploading a file using webscript, is to use a external script that uploads the file to a mounted CIFS Alfresco File System.

The problem is that the type of this new node is cm:content by default. How can I put the node content type when I upload a file?

Thanks so much! Best regards,



Santigt

kevinr
Star Contributor
Star Contributor
The problem is that the type of this new node is cm:content by default. How can I put the node content type when I upload a file?

Use the web-client to create a Rule on the target space that specializes the type on Inbound items.

Thanks,

Kevin

santigt
Champ in-the-making
Champ in-the-making
I can't create a rule, because depends on the content we want to upload. For example, we can upload a JPEG file and it can be 2 different customized types of contents, images or multimedia file.

Now, in this moment, I create 2 nodes. First one using CIFS, and the other new node, specifying the type of content, using webscripts:


var node2 = userhome.createNode(filename, typeofContent);

So then, I copy the cm:content property from the first one to the other.


node2.properties["cm:content"] = node.properties["cm:content"];

And, finally, I remove the first one (node.remove()).

That's the only idea I have to solve this probem. Any othe idea?? Thanks so much!!

Best regards,



Santigt

kevinr
Star Contributor
Star Contributor
I assume you mean using Javascript API not using webscripts (WebScripts is a framework that brings together the existing Templating and Javascript APIs into a cohesive URL addressable framework). Anyway, the cm:content property can only be copied using the JavaScript API if it is a text node (not in your case), so you want something like this instead:

var node2 = node.copy(filename);
node2.specializeType(typeofContent);

will do what you want i think.

Thanks,

Kevin

santigt
Champ in-the-making
Champ in-the-making
Ah ok! Well, the other idea runs correctly using binary file.

So, If I've understood you, I don't need to create the second node, because I can use the specializeType function to change the type of the first node (CIFS node), using webscripts.

Is that correct?? With this function, can I change the content type and put my customized type (for example, {multimedia.model}image)  ??

var node = companyhome.childByNamePath("myfile.jpg");
node.specializeType("{multimedia.model}image");
node.save();

Thanks so much Kevin!

Best regards,


Santigt

davidc
Star Contributor
Star Contributor
Added support for multipart/form-data requests.  See http://wiki.alfresco.com/wiki/Web_Scripts#formdata for docs, and http://wiki.alfresco.com/wiki/Web_Scripts_Examples#File_Upload for an example of how to support a HTML form posting meta-data and content.

This has gone into 2.1 Enterprise, but should also be available from svn HEAD soon.

santigt
Champ in-the-making
Champ in-the-making
Ok, I will wait for this HEAD code…  Smiley Very Happy

Thanks so much!! Regards,



Santigt