doujiushi9007
2019-03-29 13:08
浏览 619
已采纳

从MySQL中的BLOB读取pdf内容

i have developed a system which parses and stores emails into a MySQL database. I save the attachments as an array of objects in JSON into a MEDIUMBLOB field. Everything works almost as expected. At least when saving. When i try to read the attachments i only get back the images, but not the pdf file.

The BLOB has the following 'dummy' content:

[
{
"filename":"img1.png", "ext":"png", "type": "image/png", "size":4096, 
"dispo":"inline", "cid":"123@abc", "content":"base64_encoded binary- 
data"
},
{
"filename":"pdf1.pdf", "ext":"pdf", "type": "application/pdf", 
"size":4096, "dispo":"attachment", "cid":null, 
"content":"base64_encoded binary-data"
}
]

The attachments are written as follows: json_encode($attachmentsDB,JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT).

I debugged, but somehow when i fetch data BLOB from the DB - in this case - the last element = the pdf-file is not returned. Only the preceding image files.

When i hardcode the data and try my code it works perfectly. The data isn't truncated either.

It seems that it's not a memory problem

If anybody could give me a hint please... ?

Many thanks in advance

图片转代码服务由CSDN问答提供 功能建议

我开发了一个系统,可以将电子邮件解析并存储到MySQL数据库中。 我将附件保存为一个数组 JSON中的对象进入MEDIUMBLOB字段。 一切都按预期工作。 至少在保存时。 当我尝试读取附件时,我只返回图像,而不是pdf文件。

BLOB具有以下“虚拟”内容:

  [
 {
“filename”:“img1.png”,“ext”:“png”,“type”:“image / png”,“size”:4096  ,
“dispo”:“inline”,“cid”:“123 @ abc”,“content”:“base64_encoded binary- 
data”
},
 {
“filename”:“pdf1.pdf”  ,“ext”:“pdf”,“type”:“application / pdf”,
“size”:4096,“dispo”:“attachment”,“cid”:null,
“content”:“base64_encoded binary  -data“
} 
] 
   
 
 

附件编写如下: json_encode($ attachmentsDB,JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)。

我调试了,但不知何故,当我从数据库中获取数据BLOB时 - 在这种情况下 - 最后一个元素=不返回pdf文件。 只有前面的图像文件。

当我对数据进行硬编码并尝试使用我的代码时,它可以正常工作。 数据也不会被截断。

似乎这不是一个记忆问题

如果有人能给我一个提示,请......?

非常感谢提前

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dqellle310167 2019-03-30 06:46
    已采纳

    many thanks @Shadow ! i modified the field to LONGBLOB and now it seems to work fine! :-)

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题