ajax - JAX-RS | Download PDF from Base64 encoded data -


folks,

i have rest controller calls service base 64 encoded string represents pdf. i'm calling rest endpoint through ajax call. want user download pdf file when click on link.

here rest controller:

@get     @path("/getinvoice/{invoiceid}.pdf")     @produces("application/pdf")     @consumes(mediatype.text_html)     public response invoice(@pathparam("invoiceid") final string invoiceid) throws shoppingcartexception, unexpectederrorfault_exception,             malformedqueryfault_exception, invalidquerylocatorfault_exception, loginfault_exception, ioexception {           base64decoder decoder = new base64decoder();         byte[] decodedbytes = decoder.decodebuffer(aservice.getinvoicebody(invoiceid));         responsebuilder response = response.ok(new bytearrayinputstream(decodedbytes));         response.header("content-disposition", "attachment; filename=test.pdf");         return response.build(); } 

the service returns base64 encoded string (representing pdf) convert byte array (after google search). want user see file download popup name 'invoiceid}.pdf' when click on link. of response returned nothing happens.

would appreciate pointers or here..

update: quick test, disabled ajax call , directly called rest endpoint . able download file. perhaps due security reasons, not achievable through ajax. also, i'd users see kind 'please wait' message while processing happens in backend. i'd appreciate inputs on well.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -