cancel
Showing results for 
Search instead for 
Did you mean: 

Upload file API?

shanmmugarajak
Champ in-the-making
Champ in-the-making
Hi,

I wanted to write code using ALFRESCO API's to upload a document, which API should I use to upload.

ALFRESCO DEVELOPERS: Can you people walk me through the skeleton of how-to go about this?

Also the following questions

1. The uploaded file will be stored in back end (MySQL) - is my understanding correct?

2. Can I design my application so as to have important information about the document (something like meta data abou the doc) to be input by the user and store that as well, if so how should I go about storing the document and the meta data of it in backend, does that require a new table to be designed or can I tweak to add new fields of an existing table (that u people have designed), if so which table?

Thanks
Raja
12 REPLIES 12

paulhh
Champ in-the-making
Champ in-the-making
You have a choice of a web service API or Java APIs.  Take a look in the wiki at the developer documentation and the samples in the source.

Cheers
Paul.

shanmmugarajak
Champ in-the-making
Champ in-the-making
Hi

Thanks for the reply on Upload File. I went through UploadFileServlet.java in org.alfresco.web.app.servlet

import org.alfresco.web.bean.FileUploadBean;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

I visitied the Java API for Alfresco - http://www.alfresco.org/resource/docs/java/repository-service-api/index.html

But I couldn't spot the FileUpload related API's there (the file upload packages are mentioned above), kindly help me on this.

Thanks
Raja

ajshaw
Champ in-the-making
Champ in-the-making
take a look at http://jakarta.apache.org/commons/fileupload/

The user guide is very good. I was just looking at this today.

shanmmugarajak
Champ in-the-making
Champ in-the-making
Hi,

I understood the nuances in getting a file uploaded. I presume Alfreso uses the Apache's Common Fileupload utility. Sorry if the following issues are very rudimentary for you developers.

As JSF is used, I have my doubt about what is equivalent for HTML input type="file"? Any JSP file in Alfresco code has this?

Also I came across the possibility of doing the same upload using MyFaces
(the link is as follows
http://www.onjava.com/pub/a/onjava/2005/07/13/jsfupload.html?page=1
)
Why has Alfresco developers opted for the Commonsupload utility? Also how should I implement my input type="file" in a JSP page, from where I can utilize the FileUploadServlet class and upload a file.

Kindly reply, thanks in advance

Thanks
Raja

gavinc
Champ in-the-making
Champ in-the-making
Yes, you're quite right, MyFaces does have upload support (they use commons fileupload nehind the scenes too) but we can't currently use it as our app has to support running in a web container and a portal container.

To use the MyFaces approach you need to have a servlet filter configured in your app. In the portal environment servlet filters don't work so you can't upload files  Smiley Sad

We have had to implement a way to allow uploading in both scenarios. We therefore use the commons fileupload project directly and deal with the differences appropriately.

The page in the app that performs the upload is /projects/web-client/source/web/jsp/wizard/add-content/upload.jsp. In this file you'll notice the use of…

<r:uploadForm>‍

…this is a simple Alfresco JSF component that outputs the relevant <form> tag for the fileupload. This form tag is different for portal and servlet containers hence the reason it's slightly hidden.

So to use the file upload capability in your own app simply use <r:uploadForm> in the way upload.jsp does.

One thing to be aware of though, the upload is done in a separate form, this is because we want to upload the file to the servlet directly and not go through the JSF lifecycle.

Hope this answers your questions.

sjeek
Champ in-the-making
Champ in-the-making
I use the "UploadForm" but when I choose a file from my system, then, my message "getFileUploadSuccessMsg" will not show.

Is only the "uploadForm" necessary? or are there other components where i could be reffering to?
http://forums.alfresco.com/viewtopic.php?t=1505

greetings

gavinc
Champ in-the-making
Champ in-the-making
I would expect what you have to work, I think you have covered the full cycle.

Have you tracked down at which point it doesn't find something it should find i.e. is your QuickUpload bean found in the code you have added to browse.jsp?

If not, you could try the org.alfresco.web.app.servlet.FacesHelper object, it has a getManagedBean method that may help.

sjeek
Champ in-the-making
Champ in-the-making
I'm using now back the AddContentWizardBean and i added all the imports of upload.jsp also to browse.jsp

If i upload a file in upload.jsp, and I go back to browse.jsp, then the message getFileUploadSuccessMsg is been showed.
If i upload a file in browe.jsp, then notthing happend.

also, when I upload a file in "update-file", and then, when i go to browse.jsp, the message is been showed.

browse.jsp
<r:uploadForm>                                <td style="padding-left:4px" align=right>                                       <input type="file" name="alfFileInput"/>                         </td>                         <td style="padding-left:4px" align=left>                                        <input style="margin-left:12px;" type="submit" value="<%=Application.getMessage(FacesContext.getCurrentInstance(), "upload")%>" />                         </td>                       <%                                 AddContentWizard wiz = (AddContentWizard)session.getAttribute(AlfrescoFacesPortlet.MANAGED_BEAN_PREFIX + "AddContentWizard");                                 if (wiz == null)                                 {                                    wiz = (AddContentWizard)session.getAttribute("AddContentWizard");                                 }                                 if (wiz != null && wiz.getFileName() != null) {                                 %>                                 <td>                                 <%=wiz.getFileUploadSuccessMsg()%>                                 </td>                                <% } %>                      </r:uploadForm>                      <td>                         <h:commandButton style="margin-left:12px;" value="#{ourmsg.quick_upload}" action="#{AddContentWizard.quick}" disabled="#{AddContentWizard.fileName == null}" />‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

sam69
Champ in-the-making
Champ in-the-making
Hi sjeek !

Is your upload form working ? Because I want to do the same. Is it possible to share your code please ?
Thanks in advance !

Cheers,

Samuel