I am trying to transfer the PDF that I generated on the frontend javascript using jsPDF for Spring Framework MVC firewall. The following is the front end code I wrote:
var filename = "thefile"; var constructURL = '/daas-rest-services/dashboard/pdfPrintUpload/' + filename; var url = restService.getUrl(constructURL); var fileBytes = btoa(pdf.output()); $http.post(url, fileBytes).success(function(data) { console.log(data); }) .error(function(e, a) { console.log(e); console.log(a); });
The pdf variable was generated correctly and can confirm that it opens correctly when pdf.save ("filename") is called. The following is the Java code that was written to the Spring MVC firewall for this call:
@RequestMapping(method = RequestMethod.POST, value = "/pdfPrintUpload/{documentName}") public @ResponseBody String postPrintDocument(@PathVariable String documentName, @RequestParam byte[] fileBytes) { String methodName = "postPrintDocument"; if(logger.isLoggable(Level.FINER)){ logger.entering(CLASS_NAME, methodName); } String check; if(fileBytes != null){ check = "not null"; } else { check = "null "; } //Decoding the bytestream //Save to file location //return file location String returnValue = "HI " + documentName + " " + check; if (logger.isLoggable(Level.FINER)) { logger.exiting(CLASS_NAME, methodName); } return returnValue; }
Every time I make a request, I get 400 Errors telling me:
Error 400: Required byte [] parameter 'fileBytes' missing
I can confirm in the request payload that a large amount of data is being transferred, however the backend does not seem to want to accept the parameter.
The purpose of this is that I want to be able to receive data from pdf, and then decode it to the backend, in order to subsequently publish the PDF file in place on the server. Is there something that I am missing in my code so that these requests do not work, and is there a more efficient way to achieve this functionality?
java javascript jquery spring ajax
Joe urc
source share