2017-03-31 77 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

回答