Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Marc Heimann
file upload: getFileName() and getFile() return null
2. April 2013 06:20
Antwort

Marc Heimann

Rang: New Member

Nachrichten: 21

Eintrittsdatum: 19. Februar 2013

Neue Beiträge

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?
Jitendra Rajput
RE: file upload: getFileName() and getFile() return null
2. April 2013 06:38
Antwort

Jitendra Rajput

Rang: Liferay Master

Nachrichten: 848

Eintrittsdatum: 7. Januar 2011

Neue Beiträge

Check for enctype in form element. it should be "multipart/form-data".

1<form enctype="multipart/form-data" method="post" name="multipleUpload">
Marc Heimann
RE: file upload: getFileName() and getFile() return null
2. April 2013 06:43
Antwort

Marc Heimann

Rang: New Member

Nachrichten: 21

Eintrittsdatum: 19. Februar 2013

Neue Beiträge

now i get other errors, but this problem is solved. thank you.
vinod borole
RE: file upload: getFileName() and getFile() return null
15. Juni 2013 05:48
Antwort

vinod borole

Rang: New Member

Nachrichten: 4

Eintrittsdatum: 15. Juni 2013

Neue Beiträge

My JSP Code:
 1<div id="deliveryTypeId" style="display: none">
 2       <form enctype="multipart/form-data" method="post" name="uploadDelTypeFrm" action="${uploadDelType}" id="uploadDelTypeFrm">
 3        <table>
 4            <tr>
 5                <td>Delivery Type</td>
 6                <td><input type="file" id="deliverytypexml" name="<portlet:namespace/>deliverytypexml"></td>
 7                <td><input type="button" id="uploadDeliveryXml" value="Upload" name="uploadDeliveryXml"/></td>
 8            </tr>
 9        </table>
10    </form>
11</div>


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


I am getting sourceFileName =null and file = null
Can any one help?
Apoorva Prakash
RE: file upload: getFileName() and getFile() return null
16. Juni 2013 21:39
Antwort

Apoorva Prakash

Rang: Liferay Master

Nachrichten: 659

Eintrittsdatum: 15. Juni 2010

Neue Beiträge

vinod borole:
My JSP Code:
 1<div id="deliveryTypeId" style="display: none">
 2       <form enctype="multipart/form-data" method="post" name="uploadDelTypeFrm" action="${uploadDelType}" id="uploadDelTypeFrm">
 3        <table>
 4            <tr>
 5                <td>Delivery Type</td>
 6                <td><input type="file" id="deliverytypexml" name="<portlet:namespace/>deliverytypexml"></td>
 7                <td><input type="button" id="uploadDeliveryXml" value="Upload" name="uploadDeliveryXml"/></td>
 8            </tr>
 9        </table>
10    </form>
11</div>


My Java Code:
1try {
2     UploadPortletRequest uploadRequest = getUploadPortletRequest(actionRequest);
3         String sourceFileName = uploadRequest.getFileName("deliverytypexml");
4         File file = uploadRequest.getFile("deliverytypexml");
5} 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.