2015-05-14 41 views
0

我有一个PHP REST API已经用SLIM框架编写,我有一个API调用,它创建一个docx文件并强制文件被下载。 从PHP REST API下载docx文件与angularjs

 
    $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();
该文件已创建,我可以通过服务器读取它。
但问题是在客户端的文件已损坏

Data.get('downloadInvitation/'+ id).then(function(results) { 
     var file = new Blob([results], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' }); 
     saveAs(file, 'invitation.docx'); 
     }); 

没有人有一个想法?

回答

0

我有同样的问题。只需将responseType: 'arraybuffer'添加到您的配置中即可。