Mysql 如何在iframe中加载blob

Mysql 如何在iframe中加载blob,mysql,node.js,fetch,Mysql,Node.js,Fetch,我正在使用BLOB从MYSQL服务器数据类型获取PDF文件,但无法使其工作,请帮助 当用户单击左侧树上的树节点时。我从中获取ID,它发送到后端以获取BLOB文件,然后发送回前端 但是我不能让它工作 -----前端document.ejs文件------ --------后端--------- 我希望PDF文件加载到iframe标记上,但是当我运行代码时,chrome会说 Error Failed to load PDF document. 如果你做一个window.open(fileURL),

我正在使用BLOB从MYSQL服务器数据类型获取PDF文件,但无法使其工作,请帮助

当用户单击左侧树上的树节点时。我从中获取ID,它发送到后端以获取BLOB文件,然后发送回前端

但是我不能让它工作

-----前端document.ejs文件------

--------后端---------

我希望PDF文件加载到iframe标记上,但是当我运行代码时,chrome会说

Error
Failed to load PDF document.

如果你做一个window.open(fileURL),它能工作吗?这将确保iframe是真正的问题所在。另外,尝试输入res.setHeader('Content-Type','application/pdf')。我曾尝试使用window.open(fileURL),但它会给我相同的错误消息。我将尝试使用application/pdf设置标题,并让您知道。谢谢,所以当我将标题设置为application/pdf router.post('/getDocument',(req,res)=>{console.log(“Hello-->:”,req.body);})时,我没有从fetch调用收到任何请求。输出:Hello-->:{}我找到了这个问题的解决方案。只需将blob转换为文本即可调用查询。从hr\u dftree中选择CONVERT(使用utf8文件)file。如果要打开窗口(fileURL),它可以工作吗?这将确保iframe是真正的问题所在。另外,尝试输入res.setHeader('Content-Type','application/pdf')。我曾尝试使用window.open(fileURL),但它会给我相同的错误消息。我将尝试使用application/pdf设置标题,并让您知道。谢谢,所以当我将标题设置为application/pdf router.post('/getDocument',(req,res)=>{console.log(“Hello-->:”,req.body);})时,我没有从fetch调用收到任何请求。输出:Hello-->:{}我找到了这个问题的解决方案。只需将blob转换为文本即可调用查询。从hr_dftree中选择转换(使用utf8文件)文件
const file = {
                id : data.id,
                parent: data.parent,
                text: data.text,
                dftype:data.dftype
            };

fetch('/document/getDocument', {
                method: 'post',
                body: JSON.stringify(file),
                headers: {
                  'Accept': 'application/json',
                  'Content-Type': 'application/json',
                  'ResponseType': 'blob'
                }
            }).then( res => {
                res.blob().then(function (data){
                var file = new Blob( [data], {type: 'application/pdf'} );
                var fileURL = URL.createObjectURL(file)
                $("#fileViewer").attr("src", fileURL);  
            });
});
router.post('/getDocument', (req, res) => {

  var doc = new Doctree();

  doc.GetDoc( req.body.id, req.body.parent).then( result => {

    res.send( result[0].file );
  })
});
GetDoc(id, parent) {
        return new Promise( (resolve, reject) => {

            var query = `SELECT * FROM hr_dftree WHERE id = ${id} and parent = ${parent}`;
            pool.getConnection( (err, connection) => {
                if (err) throw err;
                connection.query(query, (err, result) => {
                    resolve(result);
                });
            })

        })
    }
Error
Failed to load PDF document.