Make form parsing aware of multiple values per key for file upload forms (enctype="multipart/form-data")
This commit is contained in:
parent
b31871fdfb
commit
dd4be4b6b6
2 changed files with 25 additions and 5 deletions
|
@ -165,9 +165,14 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
String nextKey = (String) e.nextElement();
|
String nextKey = (String) e.nextElement();
|
||||||
Object nextPart = parts.get(nextKey);
|
Object nextPart = parts.get(nextKey);
|
||||||
|
|
||||||
|
if (nextPart instanceof List) {
|
||||||
|
reqtrans.set(nextKey, ((List) nextPart).get(0));
|
||||||
|
reqtrans.set(nextKey+"_array", ((List) nextPart).toArray());
|
||||||
|
} else {
|
||||||
reqtrans.set(nextKey, nextPart);
|
reqtrans.set(nextKey, nextPart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (Exception upx) {
|
} catch (Exception upx) {
|
||||||
sendError(response, HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE,
|
sendError(response, HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE,
|
||||||
"Sorry, upload size exceeds limit of " + uploadLimit +
|
"Sorry, upload size exceeds limit of " + uploadLimit +
|
||||||
|
|
|
@ -124,12 +124,27 @@ public class FileUpload {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename != null) {
|
Object existingValue = parts.get(name);
|
||||||
MimePart part = new MimePart(filename, newb, type);
|
Object newValue = null;
|
||||||
|
|
||||||
parts.put(name, part);
|
if (filename != null) {
|
||||||
|
newValue = new MimePart(filename, newb, type);
|
||||||
} else {
|
} else {
|
||||||
parts.put(name, new String(newb, encoding));
|
newValue = new String(newb, encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existingValue == null) {
|
||||||
|
// no previous value, just add new object
|
||||||
|
parts.put(name, newValue);
|
||||||
|
} else if (existingValue instanceof ArrayList) {
|
||||||
|
// already multiple values, add to list
|
||||||
|
((ArrayList) existingValue).add(newValue);
|
||||||
|
} else {
|
||||||
|
// already one value, convert to list
|
||||||
|
ArrayList list = new ArrayList();
|
||||||
|
list.add(existingValue);
|
||||||
|
list.add(newValue);
|
||||||
|
parts.put(name, list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue