Reputation: 420
I have a project to Symfony 3. With MySQL I have a blob field for a profile user image (in bin extension).
This one is saved from my entity user with the preUpload. (I had set the path new file for test only)
But I can't read the file. How can I do this?
Upvotes: 0
Views: 625
Reputation: 2629
You can display blobs as images with the following HTML5 tag.
<img src="data:image/jpeg;base64,<base64 code here>" />
If you're using this in a Symfony controller it would look like:
/// ... controller code
$user = $this->getDoctrine()->getRepository(User:class)->find($id);
$img = $user->getImg();
// ... more controller code
return $this->render('AppBundle:yourpage.html.twig', [
'user' => $user,
'img' => base64_encode($img),
]);
And in twig, you'd display the base64 data in an image tag like this:
<img src="data:image/jpeg;base64,{{ img }}" />
Upvotes: 1