From firebase storage download file to iframe

删除回忆录丶 提交于 2019-12-13 06:45:29

问题


With below code, I can not download image to iframe. Instead, it downloaded to local drive.

in JS:

  storageRef.child('images/CopyPerson.jpg').getDownloadURL().then(function(url) {
  var iframe1 = document.getElementById('downloadedCourse');
  iframe1.src = url;
}).catch(function(error) {
  // Handle any errors
});

in html:

  <iframe id="downloadedCourse" width="800" height="500" src=""></iframe>

However, if I use img instead of iframe, it works as supposed. The reason I need use iframe is because I intend to download pdf file. Anyone knows why?


回答1:


I presume that this is because the content-disposition header is set to attachment instead of inline. Try setting the metadata to change this and see if that works:

// Obviously you only have to set the metadata once per file
// Not every time you download the URL
storageRef.child('images/CopyPerson.jpg').updateMetadata({
  "contentDisposition": "inline"  
}).then(function() {
  return storageRef.child('images/CopyPerson.jpg').getDownloadURL()
}).then(function(url) {
  var iframe1 = document.getElementById('downloadedCourse');
  iframe1.src = url;
});


来源:https://stackoverflow.com/questions/43081018/from-firebase-storage-download-file-to-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!