Spring and Angular 4 - Generate Blob or Base64 Files

1

Sorry for the inconvenience, I hope you can help me with my question! I'm developing on a platform that in front has Angular 4 and the Back is Spring , In the front I use a npm that is called pdf make , and it generates the pdf in a window or they are downloaded automatically, I occupy that when it is generated save it in my server so that later they can make use of it. PdfMake allows me to generate a blob or a base64 when generating the pdf , I can capture all the cadena of the document, but I do not know how to send it to back so that my back already do the creation of the document and save it!

I was seeing that with URL.createObjet (something like that), but I really do not know how to send it! If you could help me I would appreciate it.

    
asked by Hernan Gomez 09.07.2018 в 17:17
source

1 answer

0

If you have a Blob object, it's as simple as doing:

sendPdf(pdf: Blob) {
  this.http.post(URL,pdf);
}

where http is an instance of HttpClient

To receive it, you should use something like

@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public @ResponseBody List<Long> uploadAvatar(@RequestParam MultipartFile  avatar) {
    byte[] bytes = avatar.getBytes();
}
    
answered by 10.07.2018 / 16:57
source