0

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

2
  • 1
    Mediumblob is up to 16MB only. Base64 drastically increases the size of the data, so there may be some data truncation even if the original binary size is below 16MB. Pls include the code that stores and retrieves the files from the database. Commented Mar 29, 2019 at 13:45
  • @Shadow: ok,thanks i will check this possibility. when i download the BLOB.bin everything is fine. Commented Mar 29, 2019 at 14:25

2 Answers 2

0

Storing big data in database is bad idea because most case it will make your server slow.. rather you can copy your pdf in a folder by php script then store it's references in sql database...

Now you can easily read your pdf content from database..

Or you can check this

PHP: Upload a Pdf to SQL Database

Sign up to request clarification or add additional context in comments.

1 Comment

that is not a problem. it's a dedicated VPS 4core, 8GB RAM running Percona. Before i had the files saved in FS and referenced in DB, but the Server filled up too quick and performance was terrible.
0

As mentioned by @Shadow:

Mediumblob is up to 16MB only. Base64 drastically increases the size of the data, so there may be some data truncation even if the original binary size is below 16MB. Pls include the code that stores and retrieves the files from the database.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.