WW-4583 JakartaStreamMultiPartRequest fails on short file name and on empty file input

This commit is contained in:
Aleksandr Mashchenko
2016-01-06 19:24:56 +02:00
committed by Lukasz Lenart
parent 6fd37d86cc
commit b84fd6fe0c
@@ -384,6 +384,12 @@ public class JakartaStreamMultiPartRequest implements MultiPartRequest {
* @param location location
*/
private void processFileItemStreamAsFileField(FileItemStream itemStream, String location) {
// Skip file uploads that don't have a file name - meaning that no file was selected.
if (itemStream.getName() == null || itemStream.getName().trim().length() < 1) {
LOG.debug("No file has been uploaded for the field: {}", itemStream.getFieldName());
return;
}
File file = null;
try {
// Create the temporary upload file.
@@ -424,6 +430,10 @@ public class JakartaStreamMultiPartRequest implements MultiPartRequest {
suffix = name.substring(name.lastIndexOf('.'));
}
if (prefix.length() < 3) {
prefix = UUID.randomUUID().toString();
}
File file = File.createTempFile(prefix + "_", suffix, new File(location));
LOG.debug("Creating temporary file '{}' (originally '{}').", file.getName(), fileName);
return file;