How to get user image in session and add in html?

0

I'm developing a web application using spring boot. I already have a saved image of the user in the database, now I would like to assign the image of the user logged into the session in the profile photo of my dashboard. How to do this? I can bring other information like name and cnpf, but his image can not.

Mycontroller:

@ControllerpublicclassIndexController{@AutowiredprivateUsuarioServiceservice;@RequestMapping("/index")
public ModelAndView index(HttpSession session) {
    Usuario usuario = service.findByEmail(SecurityContextHolder.getContext().getAuthentication().getName());
    ModelAndView mv = new ModelAndView("/home");
    session.setAttribute("usuario", usuario);
    return mv;
}

My html page:

<div class="avatar">

                    <img th:src="@{/session.usuario/image/{image_id}(image_id=${session.usuario.id})}">
                </div>
                <div class="title">
                    <h1 class="h6" th:text="${session.usuario.nome}"></h1>
                    <p class="h2" th:text="${session.usuario.cnpjCpf}"></p>
                </div>
            </div>
    
asked by anonymous 29.06.2018 / 16:55

1 answer

0

Hello, in this question there is a response that may be useful, the second solution has the line:

  

mav.addObject ("userImage", base64Encoded);

Switch to:

  

session.setAttribute ("photoUser", base64Encoded);

And in JSP use:

<img src="data:image/jpeg;base64,${fotoUsuario}" />
    
04.07.2018 / 21:18