Reputation: 661
I have a PHP REST API has written with SLIM Framework, I have an api call which creates a docx file and force the file to be downloaded.
$filename = 'invitation.docx'; $templateProcessor->save($filename); header('Content-Description: File Transfer'); header('Content-type: application/force-download'); header('Content-Disposition: attachment; filename='.basename($filename)); header('Content-Transfer-Encoding: binary'); header('Content-Length: '.filesize($filename)); ob_clean(); ob_flush(); readfile($filename); exit();the file is created and i can read it via the server.
Data.get('downloadInvitation/'+ id).then(function(results) {
var file = new Blob([results], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
saveAs(file, 'invitation.docx');
});
does anyone has an idea?
Upvotes: 0
Views: 1727
Reputation: 171
I had the same problem. Just add responseType: 'arraybuffer'
to your get configuration.
Upvotes: 0