0

I am trying to make a blog post web application using firebase. Each post will display name and profile image of at the top bar/header of post.

But due to media-token associated with each profile image file uploaded on Storage is unique. if a user update their profile pic then on blog post profile image doesn't load and show 'ERROR: 403' in console.

How we can manage to show user profile image and their name along with every post? For example you can consider wall post of facebook.

1 Answers1

0

If you store the profile image URL with each blog post, you will have to update each blog post when a user's profile image URL changes. For a few strategies on how to do that, see: How to write denormalized data in Firebase. While these are for the Firebase Realtime Database, the same approaches apply to Cloud Firestore.

Alternatively, you can only store a user's profile image URL in their own user document, and then look it up when displaying a blog post from that user. In that case you would only have to update the URL in the user's own document.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Hey Frank, I am already storing user's profile data(Name, ID, Profile IMG) in firebase realtime database and blogs I am storing in Firestore Database. If I do lookup for every post done by multiple users then query may takes time to fetch for profile image urls – Prashant Kumar Oct 12 '20 at 15:55
  • Is there any way to ignore media token associated with each image, if can ignore then my problem would be solved. :) – Prashant Kumar Oct 12 '20 at 16:10
  • You can set public access on the bucket, which would remove the need for a token and allows anyone to access files in that bucket. That's a Cloud Storage setting, outside of the scope of Firebase, so I'd recommend checking the Google Cloud Storage docs for how to do it. – Frank van Puffelen Oct 12 '20 at 22:05