1.1.0 • Published 2 years ago

@purwasadr/strapi-provider-upload-firebase-storage v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@purwasadr/strapi-provider-upload-firebase-storage

Installation

# using yarn
yarn add @purwasadr/strapi-provider-upload-firebase-storage

# using npm
npm install @purwasadr/strapi-provider-upload-firebase-storage

Configuration

  • provider defines the name of the provider
  • providerOptions is passed down during the construction of the provider.
  • actionOptions is passed directly to the parameters to each method respectively. You can find the complete list of upload options and delete options

See the documentation about using a provider for information on installing and using a provider. To understand how environment variables are used in Strapi, please refer to the documentation about environment variables.

Provider Configuration

./config/plugins.js

module.exports = ({ env }) => ({
  // ...
  upload: {
    config: {
      provider: '@purwasadr/strapi-provider-upload-firebase-storage',
      providerOptions: {

        // Can be pathString or object
        serviceAccount: env('STORAGE_SERVICE_ACCOUNT'),  

        // Your bucket name. example : if the bucket URL displayed in the Firebase console 
        // is gs://bucket-name.appspot.com, pass the string bucket-name.appspot.com
        bucketName: env('STORAGE_BUCKET_NAME'),

        // Other options in initializeApp
        options: {},

        // Use custom bucket if any
        customBucket: env('STORAGE_CUSTOM_BUCKET'),  
      },
      actionOptions: {

        // Upload options see : https://googleapis.dev/nodejs/storage/latest/global.html#CreateWriteStreamOptions
        upload: {},

        // Delete options see : https://googleapis.dev/nodejs/storage/latest/File.html#delete
        delete: {},
      },
    },
  },
  // ...
});

Security Middleware Configuration

Due to the default settings in the Strapi Security Middleware you will need to modify the contentSecurityPolicy settings to properly see thumbnail previews in the Media Library. You should replace strapi::security string with the object bellow instead as explained in the middleware configuration documentation.

./config/middlewares.js

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