title: What Firebase Storage reference should be saved to RTDB/Firestore?
body: <p>I'm trying to determine the best way to reference a Firebase Storage (Google Cloud Storage) file in a direct-read database like Realtime Database or Cloud Firestore. Since a read operation to this database does not benefit from a backend that can issue tokens and cache image URLs, it is not clear to me what the most performant way is to store these references.</p>
  
  <p>I have come up with a few options and none of them are a clear winner.</p>
  
  <ol>
  <li><p>Store a path like <code>/images/foo.jpg</code> to the database, and use Storage Client SDK to generate a tokenized path with <code>storage.bucket().getDownloadURL("/images/foo.jpg")</code>.</p>
  
  <p><strong>Pros</strong>: Secure &amp; simple. </p>
  
  <p><strong>Cons</strong>: Network call for every single image you want to display hurts performance considerably.</p></li>
  <li><p>Store a tokenized path like <code>https://firebasestorage.googleapis.com/v0/b/storage-bucket-823743.appspot.com/o/images%2Ffoo.jpg?alt=media&amp;token=c6da1e33-f3ff-41e2-a6f0-bdb475a2f6d9</code> with a super long TTL.</p>
  
  <p><strong>Pros</strong>: No extra fetch on the client. </p>
  
  <p><strong>Cons</strong>: long string stored in expensive RTDB. What if that token is revoked by mistake? The database is now broken.</p></li>
  <li><p>Store a path like <code>/images/foo.jpg</code> to the Database and use public storage rules. Reconstruct into a custom static URL like <code>https://firebasestorage.googleapis.com/v0/b/storage-bucket-823743.appspot.com/o/images%2Ffoo.jpg?alt=media</code></p>
  
  <p><strong>Pros</strong>: Tiny database use, no extra client fetch, explicit public access, no token to lose. </p>
  
  <p><strong>Cons</strong>: URL encoding is super flaky, Storage could change their URL format and we'd be out of luck.</p></li>
  </ol>
  
  <p>So, those are the options I've come up with, and there may be more. Any suggestions for how to solve this issue? The issue is unique because the Firebase databases don't have the benefit of a custom server to handle a token/caching layer to resolve this problem.</p>