リクエストでjsonを受け取り、pdfファイルに応答するSpringコントローラーを作成しました。
public ResponseEntity<byte[]> generateResp(...)
byte[] gMapRep = Files.readAllBytes(file.toPath());
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.parseMediaType("application/pdf"));
httpHeaders.setContentDispositionFormData("content-disposition", "filename=report.pdf");
httpHeaders.setCacheControl("must-relative, post-check=0, pre-check=0");
return ResponseEntity
.ok()
.headers(httpHeaders)
.body(gMapRep);
Postman では問題なく動作します。いくつかのパラメーターを送信する必要があるため、POST メソッドでは必須です。しかし、応答からCycleJSでpdfファイルを取得/ダウンロードするにはどうすればよいですか。フロントエンドで試しました:
const buttonRequest$ = actions.buttonClick$
.withLatestFrom(sources.arcgisDriver.onMapLoaded,
(ev, _)=> {
return {
url: myURL,
method: 'POST',
type: 'application/json',
send: data
}
});
sources.HTTP
.filter(response => {
return !response.error && response.request.url.includes(myURL)
})
.subscribe(resp => window.open("data:application/pdf;base64, " + resp.text, '', 'height=650,width=840'));