Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-3189

blob doctrine2 not inserting file in mysql

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.4.3
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Linux Ubuntu 12.04, Mysql 5

      Description

      I have an entity mapped as:

      /**
       * @Entity @Table(name="Upload")
      **/
      class Upload
      {
      /** @Id @Column(type="integer") @GeneratedValue **/
      protected $id;
      
      /** @Column(type="string") **/
      protected $nome;
      
      /** @Column(type="blob") **/
      protected $arquivo;
      

      When I use this (WORKS)

       $query = "INSERT INTO Upload1 (name, size, type, content ) "."VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
      
       mysql_query($query)
      

      When I use this doctrine way (NOT WORKING, if you try to get this file from mysql, return a corrupted or empty file)

      $upload = new Upload();
      
      $upload-> setContent($content);
      $upload-> setName($fileName);
      $upload-> setSize($fileSize);
      $upload-> setType($fileType);
      
      $entityManager->persist($upload);
      $entityManager->flush();
      

      My html file:

      <form method="post" enctype="multipart/form-data">
      <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
      <tr> 
      <td width="246"> 
      <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
      <input name="userfile" type="file" id="userfile"> 
      </td>
      <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload    "></td>
      </tr>
      </table>
      </form>
      
      1. a.png
        258 kB

        Activity

        Hide
        Gustavo Monti Rocha added a comment -

        trying to insert this image

        Show
        Gustavo Monti Rocha added a comment - trying to insert this image
        Hide
        Gustavo Monti Rocha added a comment -

        Using:
        $entityManager->getConnection()>getConfiguration()>setSQLLogger( new Doctrine\DBAL\Logging\EchoSQLLogger());

        Getting:
        "START TRANSACTION" INSERT INTO Upload (name, type, size, content) VALUES (?, ?, ?, ?) array(4) { [1] => string(5) "a.png" [2] => string(9) "image/png" [3] => int(264547) [4] => string(270342) "‰PNG  \0\0\0 IHDR\0\0@\0\0„\0\0\0v/jõ\0\0\0sBITÛáOà\0\0\0tEXtSoftware\0gnome-screenshotï¿>\0\0 \0IDATxœìw|TÅöÀÏܲ{·$›^I¥“Лҫ€ QPô©`

        {êÏγ÷^ŸýYÀ‚ˆ\"¢ô %½m’í햙ߛ,›mÙe¾>š½÷Ι™3gæÎœ;]3ÿR P( …B¡P( …\0\0³X¾Ÿ†X]ŸÞ]ÿÂôP(\0àÜnñ¯N…B¡P( …B¡P(„B\0\0\\.÷ñ’ÊüünݺÇøîÚl¶m;æçfh4\0@BUR)”3®©šR( …B¡P( …ræa2Y+«ëV\0@4……}

        Y–<¸§×KEÙ±ãHaaßâ¢#n·\0Ãf¦§ÄÇÇþÅé¦PÎ0¨‹B¡P( …B¡P(g(„ÙttTJ5\"\0< g§æefe¥ú?3rd¿Š £V.W7ì&\0˜âF+‰ø%9uÆF\0HINø«pôx…ZÅuÉL¥“Ô(‘Ù³¯\0ú÷í}ã¶9°A‡Óãr¥Åé¯n"... } array(4)

        { [1] => string(6) "string" [2] => string(6) "string" [3] => string(7) "integer" [4] => string(4) "blob" }

        "COMMIT"

        Show
        Gustavo Monti Rocha added a comment - Using: $entityManager->getConnection() >getConfiguration() >setSQLLogger( new Doctrine\DBAL\Logging\EchoSQLLogger()); Getting: "START TRANSACTION" INSERT INTO Upload (name, type, size, content) VALUES (?, ?, ?, ?) array(4) { [1] => string(5) "a.png" [2] => string(9) "image/png" [3] => int(264547) [4] => string(270342) "‰PNG  \0\0\0 IHDR\0\0@\0\0„\0\0\0v/jõ\0\0\0sBITÛáOà\0\0\0tEXtSoftware\0gnome-screenshotï¿>\0\0 \0IDATxœìw|TÅöÀÏܲ{·$›^I¥“Лҫ€ QPô©` {êÏγ÷^ŸýYÀ‚ˆ\"¢ô %½m’í햙ߛ,›mÙe¾>š½÷Ι™3gæÎœ;]3ÿR P( …B¡P( …\0\0³X¾Ÿ†X]ŸÞ]ÿÂôP(\0àÜnñ¯N…B¡P( …B¡P(„B\0\0\\.÷ñ’ÊüünݺÇøîÚl¶m;æçfh4\0@BUR)”3®©šR( …B¡P( …ræa2Y+«ëV\0@4……} Y–<¸§×KEÙ±ãHaaßâ¢#n·\0Ãf¦§ÄÇÇþÅé¦PÎ0¨‹B¡P( …B¡P(g(„ÙttTJ5\"\0< g§æefe¥ú?3rd¿Š £V.W7ì&\0˜âF+‰ø%9uÆF\0HINø«pôx…ZÅuÉL¥“Ô(‘Ù³¯\0ú÷í}ã¶9°A‡Óãr¥Åé¯n"... } array(4) { [1] => string(6) "string" [2] => string(6) "string" [3] => string(7) "integer" [4] => string(4) "blob" } "COMMIT"
        Hide
        Steve Müller added a comment -

        This looks more like a DBAL issue. Can you please provide the error/exception message that you receive from the driver/database server? Also do you use PDOMySQL or mysqli driver?

        Show
        Steve Müller added a comment - This looks more like a DBAL issue. Can you please provide the error/exception message that you receive from the driver/database server? Also do you use PDOMySQL or mysqli driver?
        Hide
        Gustavo Monti Rocha added a comment -

        Steve,

        I'm not getting any error/expection. Table looks like insert the blob file but when I try to download it is corrupted. You could see at getting .zip file and executing it.

        I'm using PDOMysql.

        Show
        Gustavo Monti Rocha added a comment - Steve, I'm not getting any error/expection. Table looks like insert the blob file but when I try to download it is corrupted. You could see at getting .zip file and executing it. I'm using PDOMysql.
        Hide
        Marco Pivetta added a comment -

        This would probably need a data sample to reproduce the issue.

        Show
        Marco Pivetta added a comment - This would probably need a data sample to reproduce the issue.
        Hide
        Gustavo Monti Rocha added a comment -

        Marco,

        you could use project attached and image in order to reproduce.

        Show
        Gustavo Monti Rocha added a comment - Marco, you could use project attached and image in order to reproduce.
        Hide
        Marco Pivetta added a comment -

        Gustavo Monti Rocha you should actually provide a functional test for this in case, see https://github.com/doctrine/dbal/tree/master/tests/Doctrine/Tests/DBAL

        For example, the zip file you uploaded fails on various includes, and doesn't show the failures to me.

        Show
        Marco Pivetta added a comment - Gustavo Monti Rocha you should actually provide a functional test for this in case, see https://github.com/doctrine/dbal/tree/master/tests/Doctrine/Tests/DBAL For example, the zip file you uploaded fails on various includes, and doesn't show the failures to me.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Gustavo Monti Rocha
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: