简体   繁体   中英

Tomcat Liferay Small File Uploads (< 1kb)

I am running into an issue with Tomcat Liferay file uploads.

In the code I get an empty file size, causing Tomcat to return null when it tries to find the newly uploaded file in the Tomcat Temp folder.

My code:

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");

If the file is larger than 1kb, then it actually works. The real issue is that the above code errors when I actually try and actually move the file using FileUtil.copyFile() - it throws a null pointer exception saying the original file (which is supposed to be in the temp folder at this point), is null.

Pretty confused at why this happens. Here is the HTML for this:

<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>

Thanks

Looks like this solved it: https://web.liferay.com/web/josef.sustacek/blog/-/blogs/uploadportletrequest-and-file-size-limits

// This can be used to get files smaller than 1kb
uploadRequest.getFile("param", true); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM