DDC-3189: blob doctrine2 not inserting file in mysql #3971

doctrinebot opened this Issue Jun 24, 2014 · 7 comments

2 participants


Jira issue originally created by user gustavomr:

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')";


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);


My html file:

<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<td width="246"> 
<input type="hidden" name="MAX*FILE*SIZE" value="2000000">
<input name="userfile" type="file" id="userfile"> 
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload    "></td>

Comment created by gustavomr:

trying to insert this image


Comment created by gustavomr:

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

"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\0�sBIT���ÛáOà\0\0\0�tEXtSoftware\0gnome-screenshotï�¿>\0\0 \0IDATxœì�w](TÅöÀÏܲ{·$›I¥“Лҫ€ Q�P�ô©`{êÏγ÷Ÿý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@��B�UR)”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‰�ø�%9�uÆ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"


Comment created by @deeky666:

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?


Comment created by gustavomr:


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.


Comment created by @ocramius:

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


Comment created by gustavomr:


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


Comment created by @ocramius:

[~gustavomr] 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.

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment