I have an application which allows uploading of documents like .pdf, .png, .jp(e)g, .doc and .docx as shown below
<button type="button" ngf-select class="btn btn-warning btn-block"
ngf-change="vm.setCv($file, vm.person)">
Add Doc
</button>
vm.setCv = function ($file, person) {
if ($file) {
DataUtils.toBase64($file, function(base64Data) {
$scope.$apply(function() {
person.cv = base64Data;
person.cvContentType = $file.type;
});
});
}
};
These documents are stored in the form of byte array (byte[]) in the database.
Now I want to provide a link which will let someone open or download the file.
<a ng-click="vm.openFile(vm.person.cvContentType, vm.person.cv)">open</a>
function openFile (type, data) {
$window.open('data:' + type + ';base64,' + data, '_blank', 'height=300,width=400');
}
The above function works for pdf and image files but not for doc and docx files.
My question is how can I modify this code so that even if the browser is not allowing or is unable to open the .doc and .docx file, it will at least allow downloading of the file in correct format.