首页 > 解决方案 > 将 Firebase 存储中的文件保存为 .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;
            }
        });

});

标签: javascriptfirebasepdffirebase-storage

解决方案


推荐阅读