Insert PDF into MySQL

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

  1. Contributor
    Hello, do you do the insertion via phpMyAdmin?
    Have you tried renaming the .bin to .pdf?
    0
    1. Hello, yes via phpMyAdmin.
      It doesn't work either.
      0
  2. Moderator
    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
    1. Hello,
      I will follow your advice, but how do we do that? I am developing an application in Java.
      0
    2. Moderator
      @Kilkenny95Your 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
    3. For now, I am developing locally, with my app and my database on my PC.
      0
    4. Thank you anyway!
      0