我在Firebase存储中有各种存储桶,它们都包含一个html文件 . 我想要做的是通过Javascript,获取存储桶中特定HTML文件的URL,然后在新选项卡中打开它 . 当我使用'getDownloadURL'方法,并将url传递给window.open时,我发现暂时打开一个新选项卡,下载文件,然后关闭选项卡 . 理想情况下,我想完全避免下载文件,只是查看它 . 我相信这是因为URL本身的格式:https://firebasestorage.googleapis.com/v0/b/[project].appspot.com/o/[bucket]%2Fcreate.html?alt=media&token=[token]
任何人都可以帮我使用window.load来打开新标签中的html文件吗?我宁愿根本不下载文件,我需要选项卡保持打开状态 . 在此先感谢您的帮助!
var storage = firebase.storage();
var storageRef = storage.ref();
var reportFileRef = storageRef.child(currentUid + '/create.html');
reportFileRef.getDownloadURL().then(function(url) {
window.open(url, '_blank')
});
1 回答
正确设置元数据解决了Content-Disposition问题 . 这是我定义的函数,其中contenttype是“text / html”或“image / png”