I am working on a migration project from j2ee to Springboot.. I do struggle to upload a file in spring boot. As in the J2EE application "org.apache.tomcat.util.http.fileupload" is used, to upload a file, I thought as spring-boot has embedded tomcat, it is going to work, but unfortunately it doesn't. I have to work with Multipart.. I can't make it false at any time. Same thing I tried with apache common end up with same result. Here is my code .. could you please suggest me how to proceed .. your help would really appreciated..
I have two filters too.. for testing I use postman
import org.apache.tomcat.util.http.fileupload.FileItemIterator;
import org.apache.tomcat.util.http.fileupload.FileItemStream;
import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload;
@RestController
@RequestMapping("/v2")
public class PDFExtractController {
private static final long serialVersionUID = 1L;
private static Logger log = Logger.getLogger(PDFExtractController.class);
// @RequestHeader(PESConstants.CLIENT_CONTEXT) String intuit_clientcontext, // deleted from the function parameter
@RequestMapping(value = "document/{DocType}",method =RequestMethod.POST,consumes = "multipart/form-data")
public ResponseData fileUpload(@PathVariable("DocType") String docType, HttpServletRequest request){
boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);
String provider = null;
String password = null;
boolean verbose = false;
if (isMultipartContent) {
// Grab the content
try {
ServletFileUpload fileUpload = new ServletFileUpload();
FileItemIterator items = fileUpload.getItemIterator(request);
while (items.hasNext()) {
FileItemStream item = items.next();
String fieldname = item.getFieldName();
if (PESConstants.PARAM_PROVIDER.equals(fieldname)) {
provider = PdfServletMgr.getTextValue(item);
SplunkMgr.addtoMDC(MDCFieldNames.PROVIDER.getValue(), provider.trim());
}
else if (PESConstants.PARAM_VERBOSE.equals(fieldname)) {
verbose = "true".equals(PdfServletMgr.getTextValue(item));
}
if (PESConstants.PARAM_PDF.equals(fieldname) && "form".equalsIgnoreCase(docType)) {
file = PdfServletMgr.getValue(item);
}
else if (PESConstants.PARAM_PASSWORD.equals(fieldname)) {
password = PdfServletMgr.getTextValue(item);
}
}
}
}
}
}