0

I have a project to Symfony 3. With MySQL I have a blob field for a profile user image (in bin extension).

enter image description here

This one is saved from my entity user with the preUpload. (I had set the path new file for test only)

enter image description here

But I can't read the file. How can I do this?

The dump of the entity: enter image description here

2
  • 1
    You should add how you're trying to use the image blob to the question. Also this stackoverflow.com/questions/7793009/… might be useful. Commented Dec 14, 2017 at 8:57
  • i would to read the file in html src ! Commented Dec 14, 2017 at 9:00

1 Answer 1

1

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 }}" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.