Map<String, List<FormDataBodyPart>> m1 = formData.getFields();
Set<String> ss = m1.keySet();
for (String fieldName : ss) {
FormDataBodyPart n = formData.getField(fieldName);
Logger.getLogger(TemplateResource.class.getName()).log(Level.INFO, "fieldName=" + fieldName);
if (n.getContentDisposition().getFileName() != null) {//we have a file
//save it and mark it as delete on exit.
InputStream fileStream = n.getValueAs(InputStream.class);
String mimeType = n.getMediaType().toString();
File f = saveFile(n.getContentDisposition().getFileName(), mimeType, fileStream);
f.deleteOnExit();
//put only the local path of the file in the same field.
data.put(fieldName, f.getAbsolutePath());
} else {
try {
Logger.getLogger(TemplateResource.class.getName()).log(Level.INFO, "Values=" + fieldName + " === " + n.getValue());
data.put(fieldName, n.getValue());
} catch (Exception e) {
e.printStackTrace();
}
}
}