javascript - 将 Firebase 存储中的文件保存为 .pdf?
问题描述
- 在 Web 应用程序中,我希望用户能够从 Firebase Storage 下载 PDF 文件。
- 在浏览器中显示 PDF 文件可以正常工作,但是当用户尝试将文件保存在他的本地驱动器上时,它不会自动保存为 .pdf。用户必须在“另存为”窗口中的文件名末尾手动添加“.pdf”。
- 我怎样才能让它默认保存为.pdf?
这是我的代码
document.getElementById('downloadFile' + doc.id).addEventListener('click', function (e) {
e.preventDefault();
const ref = firebase.storage().ref().child('files').child(doc.id).child('file');
// Get the download URL
ref.getDownloadURL()
.then(function (url) {
window.open(url, '_blank');
}).catch(function (error) {
// A full list of error codes is available at
// https://firebase.google.com/docs/storage/web/handle-errors
switch (error.code) {
case 'storage/object-not-found':
alert('There is no file attached to this profile.')
break;
case 'storage/unauthorized':
// User doesn't have permission to access the object
break;
case 'storage/canceled':
// User canceled the upload
break;
case 'storage/unknown':
// Unknown error occurred, inspect the server response
break;
}
});
});
解决方案
推荐阅读
- scala - Spark读取错误文件路径不存在
- c# - 如何使用 ASP.NET OWIN 和 Web 窗体获取访问令牌
- vue.js - Vue:如何在兄弟组件上触发事件
- python - 如何处理python进程中的超时?
- swift - Swift NSAttributedString 添加表
- python - Pandas - 移动列值
- c# - c# wpf 访问引用中定义的对象
- xilinx - zynq 板的 AHB AP 事务错误
- soap - 如何在 oracle 服务总线中使用基本身份验证调用 http 外部肥皂服务 - 凭据应存储在 CSF KEY STORE 中
- swift - 搜索栏过滤表视图 swift 4