A provider to override the upload process to send files to Firebase Storage.
This is a Strapi provider that will upload your files to Firebase Storage.
1npm install strapi-provider-firebase-storage
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:
1{
2 name: "strapi::security",
3 config: {
4 contentSecurityPolicy: {
5 useDefaults: true,
6 directives: {
7 "connect-src": ["'self'", "https:"],
8 "img-src": [
9 "'self'",
10 "data:",
11 "blob:",
12 "storage.googleapis.com",
13 "dl.airtable.com",
14 ],
15 "media-src": [
16 "'self'",
17 "data:",
18 "blob:",
19 "storage.googleapis.com",
20 "dl.airtable.com",
21 ],
22 upgradeInsecureRequests: null,
23 },
24 },
25 },
26},
It will whitelabel images coming from Google Cloud Storage in the CORS settings.
Here is a sample usage:
1module.exports = ({ env }) => {
2 return {
3 ...
4 upload: {
5 config: {
6 provider: "strapi-provider-firebase-storage",
7 providerOptions: {
8 serviceAccount: require("path/to/my/serviceAccount.json"),
9 // Custom bucket name
10 bucket: env(
11 "STORAGE_BUCKET_URL",
12 "my-bucket-name.appspot.com"
13 ),
14 sortInStorage: true, // true | false
15 debug: false, // true | false
16 },
17 },
18 },
19 ...
20 };
21};
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 |
sortInStorage
optionBy 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.
npm install strapi-provider-firebase-storage
Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.