Skip to content

Using Firebase Storage as Object Storage

Browse the source code here.

LaunchFa.st provides you with the APIs to interact with Firebase Storage, built on top of Web Standards.

Here’s how you would set up Firebase Storage to use it with LaunchFast:

  1. In the Firebase console, open Settings > Service Accounts.

  2. Click Generate New Private Key, then confirm by clicking Generate Key.

  3. Securely store the JSON file containing the key.

  4. In the Firebase Console, Go to Storage, and save the value starting with gs://….

  5. Update the environment variables (with the key storageBucket and rest of the values obtained) via the following instructions:

Using the <Upload /> Component

To easily implemented file uploads in your application, import the Upload component in your application:

page.astro
---
import Upload from '@/components/Upload.astro'
---
<Upload />

GET files from Firebase Storage

To fetch files from Firebase Storage, pass the file’s slug as the file searchParam in /api/storage route as following:

page.astro
<script>
const getFile = new URL('/api/storage', window.location.origin)
getFile.searchParams.set('file', fileURL)
fetch(getFile.toString())
.then((res) => res.json())
.then((res) => {
const { filePublicURL } = res
console.log(filePublicURL)
})
</script>