Fórum

Upload a file + send text inside a form

thumbnail
Francois Fournel, modificado 13 Anos atrás.

Upload a file + send text inside a form

Junior Member Postagens: 99 Data de Entrada: 15/04/10 Postagens Recentes
Hi everybody,

I'am confronted to a problem where I don't manage to MIX content inside a form.
Endeed, I want to be able to send data of type text and data of type binaries.
My MVC layer developments are in Full Spring Portlet MVC.
In the JSP view if I declare :

<form:form modelattribute="formInstanceBinder" method="post" action="${actionSaveFolder}" id="saveFolderForm" enctype="multipart/mixed" name="saveFolder"></form:form>


...which is supposed to manage form with both type of data : text+binary , the upload of a file doesn't work anymore.
If I declare the form like :

<form:form modelattribute="formInstanceBinder" method="post" action="${actionSaveFolder}" id="saveFolderForm" enctype="multipart/form-data" name="saveFolder"></form:form>


I have the upload that works ! But the binding for spring bean doesn't work anymore.

Can someone tell me how to do ?

Thank you.
s t, modificado 13 Anos atrás.

RE: Upload a file + send text inside a form

Junior Member Postagens: 48 Data de Entrada: 19/10/10 Postagens Recentes
Hi Francois,

did you get your form to work?
What environment are you using?

I came along the same problem.
I have a JSP portlet. Whenever I have the enctype set to multipart/form-data (haven't seen mixed before, but it doesn't work either) I get the uploaded file via

UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);


but I don't get the text input fields. When I don't specify the enctype it seems to default to text/html and I get all the input fields from the request but of course not the uploaded file.

I found the multipart/form-data in some html examples so I assume they should work in general, also with text and file combined.


<form action="<%= sendEmailURL %>" enctype="multipart/form-data" method="post">
<input type="text" name="<portlet:namespace />fromemail">
<input type="file" name="<portlet:namespace />file">
<input type="submit" ...>
</form>



public void sendEmail(ActionRequest request, ActionResponse response) {
   String email = ParamUtil.getString(request, "fromemail");
   UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
   File file = uploadRequest.getFile("file");
}


what is wrong with the code above?

Thanks for your help
s t
thumbnail
Laszlo Kardos, modificado 13 Anos atrás.

RE: Upload a file + send text inside a form

New Member Postagens: 3 Data de Entrada: 13/11/10 Postagens Recentes
Hi,

I'm having the same problem.

I've tried both of the enctypes: multipart/form-data & multipart/mixed, but when i use them I cannot retrieve the text fields from the form.

Thanks for your help,
Laszlo
thumbnail
Laszlo Kardos, modificado 13 Anos atrás.

RE: Upload a file + send text inside a form

New Member Postagens: 3 Data de Entrada: 13/11/10 Postagens Recentes
Hi,

Ok, I've solved the problem. emoticon
If you want to get the text field, than you must use the UploadPortletRequest object in the ParamUtil.getString(.,.) method and specify enctype="multipart/mixed" in the JSP.

So the above mentioned code works this way:


public void sendEmail(ActionRequest request, ActionResponse response) {
   UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
   File file = uploadRequest.getFile("file");
   String email = ParamUtil.getString(uploadRequest, "fromemail");
}


Regards,
Laszlo
s t, modificado 13 Anos atrás.

RE: Upload a file + send text inside a form

Junior Member Postagens: 48 Data de Entrada: 19/10/10 Postagens Recentes
Thank you Laszlo

great!
If everything was that simple :-)

cheers
s t
Arsh g, modificado 13 Anos atrás.

RE: Upload a file + send text inside a form

New Member Postagens: 11 Data de Entrada: 18/02/11 Postagens Recentes
HI when i m using multipart\mixed unable to upload file it will through exception

org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/x-www-form-urlencoded

And when i used mutlipart/form-data file will upload but i m not getting liferay captch text
<liferay-ui:captcha url="<%= captchaURL %>" />
stephan t, modificado 13 Anos atrás.

RE: Upload a file + send text inside a form

Junior Member Postagens: 48 Data de Entrada: 19/10/10 Postagens Recentes
Hi Arsh,

can you please give a little bit more details on where exactly the exception is thrown, like a code snipped and/or a few more lines of the stacktrace.

I assume you set the right file endings in the portal properties?

Best
Stephan
thumbnail
Fuad Efendi, modificado 11 Anos atrás.

RE: Upload a file + send text inside a form

Regular Member Postagens: 180 Data de Entrada: 05/04/07 Postagens Recentes
stephan t:
Hi Francois,



public void sendEmail(ActionRequest request, ActionResponse response) {
   String email = ParamUtil.getString(request, "fromemail");
   UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
   File file = uploadRequest.getFile("file");
}



It's very strange... I moved existing BLOGS portlet to Liferay PortletMVC, without almost any code change, and got the same problem; solution is to get text fields from uploadRequest (instead of actionRequest). At the same time, it works perfectly in Liferay Struts environment (BLOGS portlet...)

UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
 String email = ParamUtil.getString(uploadRequest, "fromemail");