Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/easonchai/strapi-provider-upload-firebase-storage
The best Strapi Media Library provider for Firebase Storage 🔥
https://github.com/easonchai/strapi-provider-upload-firebase-storage
firebase hacktoberfest strapi
Last synced: 15 days ago
JSON representation
The best Strapi Media Library provider for Firebase Storage 🔥
- Host: GitHub
- URL: https://github.com/easonchai/strapi-provider-upload-firebase-storage
- Owner: easonchai
- Created: 2021-08-25T03:01:23.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-25T00:11:39.000Z (almost 2 years ago)
- Last Synced: 2024-04-25T16:02:13.919Z (7 months ago)
- Topics: firebase, hacktoberfest, strapi
- Language: JavaScript
- Homepage:
- Size: 451 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Firebase Storage Media Library Provider for Strapi
The best Strapi Media Library provider for Firebase Storage 🔥
Supports custom Firebase Storage buckets for Spark plan users.
## 📝 Table of Contents
- [Getting Started](#getting-started)
- [Configurations](#configurations)
- [Status](#status)
- [FAQ Section](#faq-section)
- [Contributions](#contributions)
## Getting Started
To install the package, you can either use npm or yarn
```bash
npm i strapi-provider-upload-firebase-storage# or
yarn add strapi-provider-upload-firebase-storage
```Then, you need to add a plugin config in order to use `strapi-provider-upload-firebase-storage`.
**Example**
`./config/plugins.js`
```js
module.exports = ({ env }) => ({
// ...
upload: {
provider: "firebase-storage",
providerOptions: {
serviceAccount: require("./SERVICE_ACCOUNT_KEY_PATH.json"),
bucketUrl: env("STORAGE_BUCKET_URL"),
uploadOptions: {},
deleteOptions: {},
},
},
// ...
});
```There are two environment variables you need to create in your `.env`.
**Example**
`.env`
```env
STORAGE_BUCKET_URL=.appspot.com
```| Environment Variables | Description |
| :-------------------- | :------------------------------------------------------------------------------------------------------------------------------------ |
| `STORAGE_BUCKET_URL` | The name of your Firebase storage bucket. E.g. `gs://.appspot.com` but omit the `gs://` when entering it in your `.env` |**⚠ Important Note!**
You should add your service account key (.json file) in your .gitignore to prevent it from being pushed to your repository!
That is all it takes to upload your images to Firebase storage via Strapi! 🎊
If you need help finding your service account key or bucket name, refer to the [FAQ section](#faq-section) below.
## Configurations
The initialization configuration is passed down to the provider via the `options` parameter. (e.g: `admin.initializeApp()`). You can see the complete list of options [here](https://firebase.google.com/docs/database/admin/start).
There are a few additional configurations that you can pass into the provider. You can view all the optional [upload options here](https://googleapis.dev/nodejs/storage/latest/global.html#CreateWriteStreamOptions) and [delete options here](https://googleapis.dev/nodejs/storage/latest/File.html#delete).
**Example**
`./config/plugins.js`
```js
module.exports = ({ env }) => ({
// ...
upload: {
provider: "firebase-storage",
providerOptions: {
serviceAccount: require("./SERVICE_ACCOUNT_KEY_PATH.json"),
bucketUrl: env("STORAGE_BUCKET_URL"),
options: {},
customBucket: "my-custom-bucket",
debug: true,
uploadOptions: {
resumable: false,
private: true,
},
deleteOptions: {},
},
},
// ...
});
```By default, all uploads are set to `public`. You can however change those by passing in the options into the `uploadOptions` object. Below is an example of additional options you can pass in.
| Optional Parameters | Type | Default Value | Possible Values |
| :------------------ | :-------- | :------------ | :------------------------------------------------------------------------------------------------------------------- |
| `debug` | _boolean_ | `false` | `true / false` |
| `options` | _object_ | `{}` | Refer to [official documentation](https://firebase.google.com/docs/admin/setup) |
| `customBucket` | _string_ | `undefined` | `` Only applicable if you use the Spark plan & created a custom bucket |
| `uploadOptions` | _object_ | `{}` | Refer to [official documentation](https://googleapis.dev/nodejs/storage/latest/global.html#CreateWriteStreamOptions) |
| `deleteOptions` | _object_ | `{}` | Refer to [official documentation](https://googleapis.dev/nodejs/storage/latest/File.html#delete) |
## Status
[![npm version](https://badge.fury.io/js/strapi-provider-upload-firebase-storage.svg)](https://badge.fury.io/js/strapi-provider-upload-firebase-storage)
![CI](https://github.com/easonchai/strapi-provider-upload-firebase/actions/workflows/ci.yml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/easonchai/strapi-provider-upload-firebase-storage/badge.svg?branch=main)](https://coveralls.io/github/easonchai/strapi-provider-upload-firebase-storage?branch=main)
[![Dependencies](https://status.david-dm.org/gh/easonchai/strapi-provider-upload-firebase-storage.svg)](https://status.david-dm.org/gh/easonchai/strapi-provider-upload-firebase-storage.svg)
## FAQ Section
1. Where can I get the service account key?- The service account key can be created by going to your Firebase console → Project settings → Service account → Click "Generate new private key". Then save that file anywhere safe. If saving in your repo, remember to add it into .gitignore!
2. Where can I get the storage bucket url?- Go to your Firebase console → Project settings → Storage → Click "Get Started" (if its your first time setting up Firebase Storage for the project) → Copy the URL that looks like `gs://.appspot.com` omitting the prefixed `gs://`.
3. I keep getting an error `Cannot find module './SERVICE_ACCOUNT_KEY_NAME.json'`.- The file path is relative to your `./config/plugins.js`. So if your .env is in the root of your repo (it usually is), your path will be `../.json`
## Contributions
Contributions & suggestions are welcome! Please do test it out and let me know what additional features are missing or needed. Also do let me know about any bugs you find! 😉