Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Using profile images

Avatar

Level 5

I have a solution that needs to use user profile images, but I can't seem to get the resource to adapt to a java.io.file.

Heres the relevant section of my code:

String headshotURL = user.getPath() + "/profile/photos/primary/image"; if(rr.getResource(headshotURL).adaptTo(File.class) != null) headshot = rr.getResource(headshotURL).adaptTo(File.class); else headshot = null;

Unfortunately, while rr.getResource(headshotURL) returns a resource with  getResourceType() = nt:file, I'm unable to successfuly adapt that to File.class.

The file exists, and I'm mainly using the geometrix sample users to test this out, so it's (I would imagine) relatively standard in terms of the JCR strcuture/storage.

6 Replies

Avatar

Level 10

IN your use case - what do you want to do with the File? Purhaps there is another solution. 

Avatar

Level 5

I'm writing the filepath out to sightly--headshot is a datamember for a sling model called Author, which is essentially a user with a number of unique properties on the profile node.

The headshot is used in a couple places (bylines, author listings, etc), but this is a typical case from an author info card component that will show toard the bottom of a given article page

<template data-sly-template.authorcard="${ @ author, showlink}"> <div class="media authorinfo"> <div class="media-left"> <a href="${author.archive}"> image null?    ${author.headshot == null} <img class="media-object img-circle" src="${author.headshot.path}" alt="Headshot of ${author.displayName}" /> </a> </div> <div class="media-body"> <h4 class="media-heading">${author.displayName}</h4> ${author.aboutMe} <span class="additionalinfo"> <a href="mailto:${author.email}">${author.email}</a> <a data-sly-test="${showLink}" href="${author.archive}">Author Archives</a> </span> </div> </div> </template>

Avatar

Level 5

Here's whats rendered for example:

<div class="media authorinfo"> <div class="media-left"> <a href="http://localhost:4503/content/uc/news/authors.html?id=emily.andrews@mailinator.com"> true <img class="media-object img-circle" alt="Headshot of Emily Andrews"/> </a> </div> <div class="media-body"> <h4 class="media-heading">Emily Andrews</h4> <span class="additionalinfo"> <a href="mailto:emily.andrews@mailinator.com">emily.andrews@mailinator.com</a> </span> </div> </div>

Avatar

Level 10

Actually Assets type nt:file cannot be adapted to java File Object. A File object in Java represents an actual file on a filesystem but its not with JCR.

Let me see the alternative for the same.

Avatar

Level 10

Hi Stockwell,

I got this working.. You dont have to adaptTo File.class for this to be displayed.

pass the 'headshotURL' to your html and include this URL directly like

<img class="media-object img-circle" src="${author.headshotURL}" />

This will display the author image.

You can use the available thumbnail to render is as image(like /profile/photos/primary/image/jcr:content/dam:thumbnails/dam:thumbnail_48.png) or get the property jcr:data(at /home/users/geometrixx/carlene.j.avery@mailinator.com/profile/photos/primary/image/jcr:content) and convert that binary to your input stream.