2017-04-21 166 views
0

从数据库中获取pdf作为blob对象返回pdf,并且想要使用文件名将pdf显示回浏览器。jQuery-在新标签中打开pdf,文件名为

我得到的文件背面没有问题,并且能够在新标签页中显示,但文件名看起来像 - > 64CB13D-ec93-48fa-a425-0b66n3fg

我怎么能强制文件名?

function(response){ 
    if(response.data && response.status==200){ 
     var fileContent = response.data; 
     var file = new Blob([fileContent], {type: 'application/pdf'}); 
     var fileURL = URL.createObjectURL(file); 
     window.open(fileURL, '_blank'); 
+0

您可以将blob转换为File对象,在构造函数中同时使用blob和filename,然后对该文件执行.createObjectURL()。应该管用。 https://developer.mozilla.org/en/docs/Web/API/File – Stavm

+0

@Stavm,小心分享一个代码示例? –

回答

相关问题