简体   繁体   English

点击下载Google Polymer纸厂

[英]Google Polymer paper-fab on-tap start download

Description: I have a paper-fab on my page. 描述:我的页面上有一个纸厂。 I am calling firebase-storage call inside a ready function so that I can get a link to a pdf file stored on firebase storage service.Once I get a link I assign it to the iframe (maybe I'm doing this wrong) and append it to the body. 我在ready函数中调用firebase-storage调用,以便获得指向存储在firebase存储服务上的pdf文件的链接。一旦获得链接,便将其分配给iframe(也许我做错了)并追加它到身体。

The question that I have is, is there a way to do this without using iframe? 我的问题是,有没有办法在不使用iframe的情况下做到这一点? If so how would I do it? 如果可以,我该怎么办? If not, what should I do to make the existing code work? 如果没有,我应该怎么做才能使现有代码正常工作?

Below are the polymer component and call I'm making inside ready life cycle. 以下是聚合物组分,我正在准备好的生命周期内打电话给我。

 <paper-fab mini icon="file-download" id="fileDownload" on-click="downloadFile"></paper-fab> <firebase-storage id="storage" app-name="website" path="/path-to-pdf-file"></firebase-storage> 

 downloadFile: function() { // Create an IFRAME. var iframe = document.createElement("iframe"); // Point the IFRAME to GenerateFile iframe.src = this.filepath; // This makes the IFRAME invisible to the user. iframe.style.display = "none"; // Add the IFRAME to the page. This will trigger a request to GenerateFile now. document.body.appendChild(iframe); }, ready: function() { const storage = this.$.storage; storage.getDownloadUrl(storage.path).then(function(url) { this.filepath = url; }.bind(this)).catch(function(err) { console.debug('something really bad happened'); }); } 

Using iframe I get this error. 使用iframe时出现此错误。

web-home.html:97 Resource interpreted as Document but transferred with MIME type application/pdf: web-home.html:97资源被解释为文档,但以MIME类型application / pdf传输:

Help will be greatly appreciated. 帮助将不胜感激。

Here is one simple solution 这是一个简单的解决方案

<a href="path/to/download">
    <paper-fab></paper-fab>
</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM