cancel
Showing results for 
Search instead for 
Did you mean: 

WebScript File Upload Using Java

subwiz
Champ in-the-making
Champ in-the-making
We are developing our WebScripts using Java (extending AbstractWebScript). We want to implement the same functionality described here:

http://wiki.alfresco.com/wiki/Web_Scripts_Examples#File_Upload

using Java WebScript. Are there any community provided examples for this?
6 REPLIES 6

rogier_oudshoor
Champ in-the-making
Champ in-the-making
Actually, this is impossible due to some bad code in the webscript layer. The layer will automatically process any multi-part field for you, and hide the raw results (including the file). This way, there is no way to access the file through Java without correcting the Alfresco code.

What you can also do, is use Java for what you want to use Java for, and then have a very simple piece of javascript handle the file upload. The webscript system will (try to) call the javascript file, even when you have plugged in your Java class.

subwiz
Champ in-the-making
Champ in-the-making
Just to add context to our discussion:

http://forums.alfresco.com/en/viewtopic.php?f=7&t=17197

We have the upload form designed as a WebScript, and we want to encrypt the uploaded stream before writing to Alfresco. So I think your solution will not apply in our case. Are there any other possibilities in our case (one possibility is to write a proxy web-app which does the encryption before upload–but we have already written lots of stuff using WebScripts associated with upload).

This seems to be the issue tracking what we are discussing: https://issues.alfresco.com/jira/browse/ALFCOM-1747

rogier_oudshoor
Champ in-the-making
Champ in-the-making
In your case, i would recommend creating your own Service Class. If you create & register a Java class with the attribute setting
parent="baseJavaScriptExtension"
in the spring configuration, and add the subnode
 <property name="extensionName" value="myJavaService" />  
you can access it's methods from JavaScript by calling
myJavaService.someMethod(arg1); 
.

You could extract the contents in javascript, pass whatever you want as arguments to your Java class, and have your java class do whatever it wants to it (including writing it).

icemaker
Champ in-the-making
Champ in-the-making
Actually, this is impossible due to some bad code in the webscript layer. The layer will automatically process any multi-part field for you, and hide the raw results (including the file). This way, there is no way to access the file through Java without correcting the Alfresco code.

What you can also do, is use Java for what you want to use Java for, and then have a very simple piece of javascript handle the file upload. The webscript system will (try to) call the javascript file, even when you have plugged in your Java class.

In which order are they called?
Is the javascript file called before/after the java file has been executed or is it executed at the same time ?

What I want to do is send an email to specific users once the file has been uploaded.
The java part will send the email and the javascript part will process the upload.

The email has to be sent only if the upload successes.

rogier_oudshoor
Champ in-the-making
Champ in-the-making
Java Webscript controller is called first, Javascript Webscript controller is called second. However, if you create your own service Java class, you can call that service class from your javascript Webscript controller.

jaime17
Champ in-the-making
Champ in-the-making
We are developing our WebScripts using Java (extending AbstractWebScript). We want to implement the same functionality described here:

http://wiki.alfresco.com/wiki/Web_Scripts_Examples#File_Upload

using Java WebScript. Are there any community provided examples for this?
Glad to hear that you are developing our WebScripts using Java (extending AbstractWebScript)…
Hope you will make it well… Good luck!


_________________
Indianapolis SEO