Insert PDF into MySQL

Kilkenny95 Posted messages 178 Status Member -  
Kilkenny95 Posted messages 178 Status Member -
Hello everyone,

I'm trying to insert a pdf file into my table, so I've created a field called "pdf" of type LONGBLOB. When I insert it, there are no problems. But once I want to reopen the file (via phpMyAdmin), by clicking directly on the cell of my "pdf" column, Adobe tells me that it could not open it because the file type is not supported or is damaged.

Additionally, when I click on it, it also downloads my pdf as .bin

So I feel like the problem comes from the fact that phpMyAdmin seems to convert my pdf into .bin

If anyone could help me, thank you in advance.

2 answers

yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   Ambassadeur 1 588
 
Hello, do you do the insertion via phpMyAdmin?
Have you tried renaming the .bin to .pdf?
0
Kilkenny95 Posted messages 178 Status Member
 
Hello, yes via phpMyAdmin.
It doesn't work either.
0
jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
 
Hello,

I would like to point out that we avoid storing files directly in the database....
Instead, we will store the files on the server and only put the path to that file in the database.

Why?... Because the fuller the table is... the slower it becomes.....
And often, the available space on the server for files (with a host...) is much greater than the available space for the database itself.

And if you really want to keep your PDF in the database.... then open it from your PHP code (instead of trying to open it directly in phpmyadmin)
for example via
 <object data="data:application/pdf;base64,<?php echo base64_encode($lecontenuduchampblob) ?>" type="application/pdf" style="height:200px;width:60%"></object> 


--
Best regards,
Jordane
0
Kilkenny95 Posted messages 178 Status Member
 
Hello,
I will follow your advice, but how do we do that? I am developing an application in Java.
0
jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830 > Kilkenny95 Posted messages 178 Status Member
 
Your Java application... do you code a "server" part and a "client" part?

I have the impression that you want to create a "client" application that would directly access the database remotely... which is not a good practice.
A "remote/client" application should never access a database directly.
It will use (we say "consume") web services.
The web services will be set up on the server, and they will be the ones to directly access the database.


As for displaying a PDF in Java... I don't know. You need to look online.
0
Kilkenny95 Posted messages 178 Status Member
 
For now, I am developing locally, with my app and my database on my PC.
0
Kilkenny95 Posted messages 178 Status Member
 
Thank you anyway!
0