Skip to content
Advertisement

Unable to download file (PPTX) in AngularJS

Scenario

I want to make an existing PHP script dynamically generating a PPTX (Microsoft PowerPoint File) (Risk Mitigation Event Summary) accessible via an API call to specifically cause AngularJS front end to download the file.

So far my script contains a function called generatePresentation (actual name below). It works opening the script in a browser and produces dynamically generated file using PhpPresentation generation library.

The question is as follows.

How do I make the PowerPoint successfully download without any problems?

Any Help Would Be Appreciated.

Existing PowerPoint Download Function

JavaScript

Sample Input (“Risk Event” list of elements to generate PowerPoint file)

JavaScript

Sample PowerPoint File Generated

enter image description here

AngularJS download function

JavaScript

PowerPoint Error Message when downloading enter image description here

Sample Output in Browser from API (The file contents)

enter image description here

Advertisement

Answer

Use of the following three functions (first two are for encoding decoding a string) helped achieve a successful downloadable file.

Link to Solution which requires use of the first two functions.

https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_5_%E2%80%93_rewrite_the_DOMs_atob()_and_btoa()_using_JavaScript’s_TypedArrays_and_UTF-8

PHP

JavaScript

JS

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement