2017-03-31 76 views
1

我遇到了Tomcat Liferay文件上傳的問題。Tomcat Liferay小文件上傳(<1kb)

在代碼中,我得到一個空文件大小,導致Tomcat在嘗試在Tomcat Temp文件夾中查找新上載的文件時返回null。

我的代碼:

File[] files = uploadRequest.getFiles("fileupload"); 
for(File f : files) { 
    (f.length == 0) { /* This is always true (null file upload) */ } 
    FileUtil.copyFile(f, newfile); // This throws a null pointer exception 
} 

// Also happens with any other attempts at getting the file from the form, like this (below). 
// None of these work with files < 1 kb 
FileItem[] fileitems = uploadRequest.getMultipartParameterMap().get("fileupload"); 

如果文件大於1KB大,那麼它的實際工作。真正的問題是,當我實際嘗試並使用FileUtil.copyFile()實際移動文件時發生上述代碼錯誤 - 它會拋出一個空指針異常,指出原始文件(應該在此時位於臨時文件夾中),一片空白。

爲什麼發生這種情況很困惑。下面是這個HTML:

<aui:form action="<%=uploadFileURL%>" enctype="multipart/form-data" method="POST"> 
    <aui:input type="hidden" value="/" name="selected_dir_input"/> 
    <b>Selected Folder: </b> 
    <span id="selected_folder">/Home/User/Desktop/Some_Selected_file.ext</span> 
    <aui:input type="file" name="fileupload" multiple="true"/> 
    <aui:button name="Upload" value="Upload" type="submit" /> 
</aui:form> 

感謝

+0

你用什麼庫多工作?你如何獲得'uploadRequest'和它有什麼類型? –

+0

'UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);'和它的包'com.liferay.portal.kernel.upload.UploadPortletRequest' – Billy

回答