derrickrozay's avatar

Binary column not saving full picture (but the same pic compressed is)

I am trying to save pictures in my database (I know its not standard practice but I have to) and the problem is a 100kb picture doesnt display in full but if I compress the same picture down to 40kb (using compressjpeg.com) it displays in full. I am using Laravel/Lumen as my backend and angular2 as my front end

Displaying it (angular2)

<div class="col-sm-9" *ngFor="let info of info2">
  <img [src]="'data:image/JPEG;base64,' + info.pic"/>
</div>

How I'm saving it to the database

$file = $request->file('image');
$imagedata = file_get_contents($file);
$base64 = base64_encode($imagedata);

if (DB::table('paint')->where('id', 1)
    ->update(['pic' => $base64]))
{
}

The column in the table

$table->binary('pic')->nullable();
0 likes
1 reply
derrickrozay's avatar
derrickrozay
OP
Best Answer
Level 1

I was able to solve the problem by editing the table and changing the pic column from binary to mediumblob

Please or to participate in this conversation.