npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

strapi-provider-firebase-storage

v1.0.4

Published

A storage provider for the Strapi CMS that manages file uploads to Firebase Storage

Downloads

791

Readme

Strapi Provider Firebase Storage

This is a Strapi provider that will upload your files to Firebase Storage.

Installation

npm install strapi-provider-firebase-storage

Note on CORS options

You may run into an issue displaying the image where CORS is blocking it. If that happens open ./config/middwares.js and replace strapi::security with this:

{
  name: "strapi::security",
  config: {
    contentSecurityPolicy: {
      useDefaults: true,
      directives: {
        "connect-src": ["'self'", "https:"],
        "img-src": [
          "'self'",
          "data:",
          "blob:",
          "storage.googleapis.com",
          "dl.airtable.com",
        ],
        "media-src": [
          "'self'",
          "data:",
          "blob:",
          "storage.googleapis.com",
          "dl.airtable.com",
        ],
        upgradeInsecureRequests: null,
      },
    },
  },
},

It will whitelabel images coming from Google Cloud Storage in the CORS settings.

Usage

Here is a sample usage:

module.exports = ({ env }) => {
  return {
    ...
    upload: {
      config: {
        provider: "strapi-provider-firebase-storage",
        providerOptions: {
          serviceAccount: require("path/to/my/serviceAccount.json"),
          // Custom bucket name
          bucket: env(
            "STORAGE_BUCKET_URL",
            "my-bucket-name.appspot.com"
          ),
          sortInStorage: true, // true | false
          debug: false, // true | false
        },
      },
    },
    ...
  };
};

Config Options

| Option | Is Required | Default | Notes | | :--------------- | :---------- | :------ | :------------------------------------------------------------------------------------------------------------------------- | | serviceAccount | true | none | This is just the path to your service account file | | bucket | false | none | If you leave this blank it should go to your default bucket, but I'd recommend putting your default bucket name anyway | | sortInStorage | false | true | This will sort files in your firebase storage bucket into folders | | debug | false | false | This will just log all the steps to the console |

Notes on the sortInStorage option

By default Strapi will just output all the files in the default bucket with no folder structure (even if you make folders in the Strapi admin UI). Strapi also creates variants of files (like iamges ex. thumbnails) so if you upload an image to Strapi you'll actually have like a few variants of it actually uploaded to Firebase.

If you were to look at that in Firebase it would look like total chaos. So what I did was create a couple of functions that will upload your files based on mime type as well as sort all variants of an image under a single folder. If you wanted to do something else with those images (for example create triggers for uploads for specific folders) they will be sorted nicely for you.

Alos be really careful toggling the sortInStorage option. If you have it on, upload some files, then turn it off the delete function could break for the files that were uploaded when it was turned on.