gpt4 book ai didi

java - Tomcat Liferay 小文件上传(< 1kb)

转载 作者:行者123 更新时间:2023-11-28 22:26:24 26 4
gpt4 key购买 nike

我遇到了 Tomcat Liferay 文件上传问题。

在代码中,我得到一个空文件大小,导致 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>

谢谢

最佳答案

看起来像这样解决了: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);

关于java - Tomcat Liferay 小文件上传(< 1kb),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43148641/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com