首页 > 解决方案 > Safari 无法正确下载文件名

问题描述

I've a file called "Screen Shot 2552018-09-10 at 08.17.168792378923879423789324789234789234789023478943829009872438723487990724490237842378947289379802323478923478974283923487943287937428978932478324789873924789324879034278978923478923478923470897890432879 (1).png" and my code is using command link to get it. 这在 Chrome 中运行良好,但在 Safari 中却不行。Safari 会更改路径 URL 中某些内容的文件名。

例如:url 是 localhost:8080/app/documents/771 所以这个文件被重命名为 771

野生动物园 14

Safari 中“显示下载”的屏幕截图

铬合金

Chrome 中“下载”的屏幕截图

代码

<h:commandLink value="#{document.fileName}" ajax="false" immediate="true"
 onclick="PrimeFaces.monitorDownload(PF('blockUIWV').show(), PF('blockUIWV').hide()); _paq.push(['trackEvent', 'Documents', 'Download document,'Download']);">
 <p:fileDownload value="#{bean.downloadDocument(document.myDocument)}" />
</h:commandLink>

我看到 HTML5 有一个下载属性,所以我试图强制它。

代码

<h:commandLink value="#{document.filename}" ajax="false" immediate="true"
 pt:download="#{document.filename}
 onclick="PrimeFaces.monitorDownload(PF('blockUIWV').show(), PF('blockUIWV').hide()); _paq.push(['trackEvent', 'Documents', 'Download document,'Download']);">
 <p:fileDownload value="#{bean.downloadDocument(document.myDocument)}" />
</h:commandLink>

即使进行了此更改,该文件的名称也不正确。但现在名称是“文档”(我的网址的一部分)。Safari 出了什么问题,我该如何解决?

环境

标签: jsfprimefacessafari

解决方案


因此,经过研究,我认为您应该将此问题报告给 Apple。

见 PF 票:https ://github.com/primefaces/primefaces/issues/6327

此文件名在 Chrome、Firefox、MS Edge 中运行良好。它仅在 Safari 中不起作用。

在 PF 9.0 中,我们添加了一个新功能 AJAX 文件下载,它确实可以工作https://github.com/primefaces/primefaces/issues/5978并且 Safari 会正确下载文件名。


推荐阅读