I think the problem is with the third parameter of the download function which is the MineType. since it is a .docx, you may let the brower detect the type by call it like this:
Took from documentation of download.js
The MIME content-type of the file to download. While optional, it helps the browser present friendlier information about the download to the user, encouraging them to accept the download.
I figured the answer to this would be easy to find online, but it is not. All the resources I can find describe building a button or an HTML thing that causes a file to be downloaded, but I need this download to be triggered via a line of code within a function that is already running. (I already have the .docx saved online. I am not trying to live generate the .docx using the .js code).
I tried using this download.js code, but I couldn’t get it to work. When I do something like the code below, it just downloads a .txt file called “file_name.txt” where the text is “/filepath.docx/”
download('/filepath.docx', 'file_name', 'test')
Any help would be much appreciated. Also, I know even less about HTML.
I think I found a solution:
var a = document.createElement('A');
var filePath = 'file_path.docx;
a.href = filePath;
a.download = filePath.substr(filePath.lastIndexOf('/') + 1);
I found this solution on StackOverflow here and here.