Skip to content

sanjay-io/strapi-provider-upload-cloudflare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

strapi-provider-upload-cloudflare

npm version npm downloads

Non-Official Cloudflare Upload Provider for Strapi

This has only been tested with Strapi 4.

To find your Cloudflare accountId and apiKey, log into Cloudflare and click "Images". On that page you should see "Account ID" under Developer Resources. For apiKey, if you click the "Use API" tab you'll see a link next to "API Token" to generate an apiKey. The only permission that API Token needs is "Account.Cloudflare Images".

If you have multiple image variants the first one will be selected unless you specify the "variant" parameter.

Installation

# using yarn
yarn add strapi-provider-upload-cloudflare

# using npm
npm install strapi-provider-upload-cloudflare

Configurations

Your configuration is passed down to the provider.

See the using a provider documentation for information on installing and using a provider. And see the environment variables for setting and using environment variables in your configs.

Provider Configuration

./config/plugins.js

module.exports = ({ env }) => ({
  // ...
  upload: {
    config: {
      provider: 'strapi-provider-upload-cloudflare',
      providerOptions: {
        accountId: env('STRAPI_UPLOAD_CLOUDFLARE_ACCOUNT_ID'),
        apiKey: env('STRAPI_UPLOAD_CLOUDFLARE_API_KEY'),
        variant: env('STRAPI_UPLOAD_CLOUDFLARE_VARIANT'),
      },
    },
  },
  // ...
});

To get your accountId and apiKey see the top of this README.

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:', 'imagedelivery.net'],
          'media-src': ["'self'", 'data:', 'blob:', 'imagedelivery.net'],
          upgradeInsecureRequests: null,
        },
      },
    },
  }, 
  // ...
];

Resources

Links