Load a default image when not picked

Hi there,

I’m new to Glide and I’m starting with the Instagram look alike template to build my own app. I followed the dedicated tutorial but I still have some issues to do the same and to implement other things.

I wonder how I can proceed to display a default image if the user does not select one with the image picker, not to see a blank square in the feed.

Thanks for your help,
Jérémy

Hi Jeremy,

For this purpose, it’s quite simple.

First, you have the image picker which allows your users to pick a profile image, pointing on a column. OK.

Add a template column in the Glide data editor, containing the image or url of the default picture.

Then, add an if/then/else column in the data editor : if “user image” is empty then “default image” else “user image”. This way, this if column will always contains an image, either the user’s one, either the default one.

In your app, the image component will point on the if/then/else column.

That’s it!

4 Likes

Great quick explanation. I’ve done this in some of my apps and it really gives a way more polished look (as opposed to the first letters of the users’ names). It’s especially awesome when doing a relation to the user profile. Having a default “person icon” next to the name really makes it look like a link to the person’s profile.

Only thing left to refine for profile images is the ability to set an image as the app user’s profile image (for the menu icon and comments icon).

Hi Christophe,

Thank you for your help. It really seem the appropriate answer!
However I can’t manage to do that part : “Add a template column in the Glide data editor, containing the image or url of the default picture.”

How to actually upload the image in the data editor (and not the Google sheet right?)?

Moreover, it seems that the image picker won’t point on the if/then/else column if it is absent from the Google sheet.

Thanks again for your help,

You could do that. I prefer placing the image URL in a sheet of “Resources” that also include my choice component options. Then I use a single value data column to pull in the image.

You are trying to place the location of the image from your desktop. You first need to either upload it to google drive and share it to get a public url. Or you could temporarily drag and drop the image into an image component, which will upload the image to glide’s firebase server, or you could temporarily use an image picker component to upload the image. Once the image is uploaded, you will have a url that you can use for the template column.

2 Likes

Exactly! My previous explanation misses this detail sorry :pray:

2 Likes