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

roman
Champ in-the-making
Champ in-the-making
hey guys,

same scenario…

got a wizard derived from AddContentDialog which should upload a file in the first step.

wizard configuration is working so far (i can navigate through the steps and so on).
the first step (add-content.jsp) should contain the upload form.

this is my code:

<%
boolean fileUploaded = false;

AddMarketingDocumentWizard wiz = (AddMarketingDocumentWizard)FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "AddMarketingDocumentWizard");
if (wiz != null && wiz.getFileName() != null){
   fileUploaded = true;
}
%>


<%– load a bundle of properties with I18N strings –%>
<f:loadBundle basename="alfresco.messages.webclient" var="msg"/>
<f:loadBundle basename="alfresco.extension.webclient" var="swipemsg"/>


<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/validation.js"> </script>
<a:errors message="#{msg.error_dialog}" styleClass="errorMessage" />

<%
if (fileUploaded)
{
PanelGenerator.generatePanelStart(out, request.getContextPath(), "yellowInner", "#ffffcc");
out.write("<img alt='' align='absmiddle' src='");
out.write(request.getContextPath());
out.write("/images/icons/info_icon.gif' />  ");
out.write(wiz.getFileUploadSuccessMsg());
PanelGenerator.generatePanelEnd(out, request.getContextPath(), "yellowInner");
out.write("<div style='padding:2px;'></div>");
}
%>

<h:panelGrid columns="1" cellpadding="2" style="padding-top: 4px; padding-bottom: 4px;"
width="100%" rowClasses="wizardSectionHeading">
<h:outputText value=" #{msg.upload_content}" escape="false" />
</h:panelGrid>


<%– File upload formular –%>
<r:uploadForm>
<table>
<tr>
<td><h:outputText id="text1" value="1. #{msg.locate_content}"/></td>
</tr>
<tr>
<td colspan="3">
<input style="margin-left:12px;" type="file" size="75" name="alfFileInput"/>
</td>
</tr>
<tr><td class="paddingRow"></td></tr>
<tr>
<td class="mainSubText" colspan="3">
2. <%=Application.getMessage(FacesContext.getCurrentInstance(), "click_upload")%>
</td>
</tr>
<tr>
<td colspan="3">
<input style="margin-left:12px;" type="submit" value="<%=Application.getMessage(FacesContext.getCurrentInstance(), "upload")%>" />
</td>
</tr>
</table>

</r:uploadForm>


totally simple, show some fields + the upload form using <r:uploadForm>
(Alfresco specific tag) and a code snippet which should check if the file has been uploaded and then insert a Message (getFileUploadSuccessMsg()).

BUT IT DOESN'T WORK!

i've found the problem but i don't know how to solve it:

the source code of the output is 'correct':


<form name='upload-form' acceptCharset='UTF-8' method='post' enctype='multipart/form-data' action='/alfresco/uploadFileServlet'>
<input type='hidden' name='return-page' value='/alfresco/faces/jsp/wizard/container.jsp'>

<table>
<tr>
<td></td>
</tr>
<tr>
<td colspan="3">
<input style="margin-left:12px;" type="file" size="75" name="alfFileInput"/>
</td>
</tr>

<tr><td class="paddingRow"></td></tr>
<tr>
<td class="mainSubText" colspan="3">
2. Click upload
</td>
</tr>
<tr>
<td colspan="3">
<input style="margin-left:12px;" type="submit" value="Upload" />
</td>
</tr>
</table>

</form>



BUT THE GENERATED CODE OF THE PAGE is:


<input name="return-page" value="/alfresco/faces/jsp/wizard/container.jsp" type="hidden">

<table>
<tbody><tr>
<td></td>
</tr>
<tr>
<td colspan="3">
<input style="margin-left: 12px;" size="75" name="alfFileInput" type="file">
</td>
</tr>

<tr><td class="paddingRow"></td></tr>
<tr>
<td class="mainSubText" colspan="3">
2. Click upload
</td>
</tr>
<tr>
<td colspan="3">
<input style="margin-left: 12px;" value="Upload" type="submit">
</td>
</tr>
</tbody></table>


there are no upload-form tags in the code. this form tag should contain 'alfresco/uploadFileServlet' as action to upload the file
instead it submits the parent form which has '…wizard/container.jsp' as action.

where are the form tags and how can i manage this problem.

please help.

best regards

PS: i've found an error message in the firefox error console:
Warning: Form contains a file input, but is missing method=POST and enctype=multipart/form-data on the form.  The file will not be sent.
Source File: http://localhost:9080/alfresco/faces/jsp/wizard/container.jsp
Line: 0

i think it is because the form tags are missing…

gavinc
Champ in-the-making
Champ in-the-making
For this to work correctly you need to close the JSF form before starting the r:uploadForm tag, then after the upload form, open another JSF form for the remainder of the page. See the original add-content-dialog.jsp page for an example of this.

However, I have a feeling this technique does not work from inside a 'snippet' page used in the dialog/wizard framework. Due to the way the dialog/wizard framework works you can not split forms across the snippet page. It's worth trying though.

If you look at the original add-content-dialog.jsp page you'll notice that it is a 'full' page and not a 'snippet' page.

Hope this helps.

roman
Champ in-the-making
Champ in-the-making
Thanks for the answer Gavin,

hmm, it will be very complex 🙂 but I'll try it  😎

the problem is just that i'm not starting the parent form.
It's part of the wizard dialog. i'll look for a workaround, maybe.

do you have any suggestions how i can do it better?
with a dialog instead of the wizard?

thanks for your help and thanks to Dave  :wink:
roman
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.