Fórum

file upload: getFileName() and getFile() return null

Marc Heimann, modificado 11 Anos atrás.

file upload: getFileName() and getFile() return null

New Member Postagens: 21 Data de Entrada: 20/02/13 Postagens Recentes
Hi,

i'm trying to get a working file upload and i found many examples using the UploadPortletRequest class (i'm still a beginner). the view.jsp contains:
<input type="file" name="Photo_0" size="50">

in the portlet class the following method is called:
public void addForm( ActionRequest request, ActionResponse response )
{
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
String sourceFileName = uploadRequest.getFileName("Photo_0");
System.out.println("sourceFileName: " + sourceFileName);
File file = uploadRequest.getFile("Photo_0");
bytes = FileUtil.getBytes(file);
System.out.println("bytes: " + bytes);
...
}

when i pick a file and submit, i get the following output:
sourceFileName: null
bytes: null

i've also altered view.jsp e.g. using <portlet:namespace/> or the id attribute, but i always get null. Where can i look into now?
thumbnail
Jitendra Rajput, modificado 11 Anos atrás.

RE: file upload: getFileName() and getFile() return null (Resposta)

Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens Recentes
Check for enctype in form element. it should be "multipart/form-data".

Marc Heimann, modificado 11 Anos atrás.

RE: file upload: getFileName() and getFile() return null

New Member Postagens: 21 Data de Entrada: 20/02/13 Postagens Recentes
now i get other errors, but this problem is solved. thank you.
vinod borole, modificado 10 Anos atrás.

RE: file upload: getFileName() and getFile() return null

New Member Postagens: 4 Data de Entrada: 15/06/13 Postagens Recentes
My JSP Code:
<div id="deliveryTypeId" style="display: none">
       <form enctype="multipart/form-data" method="post" name="uploadDelTypeFrm" action="${uploadDelType}" id="uploadDelTypeFrm">
		<table>
			<tbody><tr>
				<td>Delivery Type</td>
				<td><input type="file" id="deliverytypexml" name="<portlet:namespace/>deliverytypexml"></td>
				<td><input type="button" id="uploadDeliveryXml" value="Upload" name="uploadDeliveryXml"></td>
			</tr>
		</tbody></table>
	</form>
</div>


My Java Code:
try {
	 UploadPortletRequest uploadRequest = getUploadPortletRequest(actionRequest);
         String sourceFileName = uploadRequest.getFileName("deliverytypexml");
         File file = uploadRequest.getFile("deliverytypexml");
} catch (Exception e) {  }


I am getting sourceFileName =null and file = null
Can any one help?
thumbnail
Apoorva Prakash, modificado 10 Anos atrás.

RE: file upload: getFileName() and getFile() return null

Liferay Master Postagens: 658 Data de Entrada: 15/06/10 Postagens Recentes
vinod borole:
My JSP Code:
<div id="deliveryTypeId" style="display: none">
       <form enctype="multipart/form-data" method="post" name="uploadDelTypeFrm" action="${uploadDelType}" id="uploadDelTypeFrm">
		<table>
			<tbody><tr>
				<td>Delivery Type</td>
				<td><input type="file" id="deliverytypexml" name="<portlet:namespace/>deliverytypexml"></td>
				<td><input type="button" id="uploadDeliveryXml" value="Upload" name="uploadDeliveryXml"></td>
			</tr>
		</tbody></table>
	</form>
</div>


My Java Code:
try {
	 UploadPortletRequest uploadRequest = getUploadPortletRequest(actionRequest);
         String sourceFileName = uploadRequest.getFileName("deliverytypexml");
         File file = uploadRequest.getFile("deliverytypexml");
} catch (Exception e) {  }


I am getting sourceFileName =null and file = null
Can any one help?


See this: http://www.liferay.com/community/forums/-/message_boards/message/25668950

HTH.