Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with strapi-provider-cloudflare-r2 #44

Open
gonwms opened this issue Jun 18, 2024 · 1 comment
Open

Compatibility with strapi-provider-cloudflare-r2 #44

gonwms opened this issue Jun 18, 2024 · 1 comment

Comments

@gonwms
Copy link

gonwms commented Jun 18, 2024

Is it posible to use strapi-plugin-image-optimizer along strapi-provider-cloudflare-r2 ?
I can use both separatelly but togetter they don't work. Any ideas?

Thanks in advice!

// plugin.ts configuration

export default ({ env }) => ({
  "drag-drop-content-types": {
    enabled: true,
  },
  "image-optimizer": {
    enabled: false,
    config: {
      include: ["jpeg", "jpg", "png", "tiff", "webp", "avif", "gif"],
      // exclude: ["gif"],
      formats: ["webp"],
      sizes: [
        {
          name: "sm",
          width: 480,
          withoutEnlargement: true,
        },
        {
          name: "md",
          width: 960,
          withoutEnlargement: true,
        },
        {
          name: "xl",
          width: 1920,
          // withoutEnlargement: true,
        },
        {
          // Uses original size but still transforms for formats
          name: "original",
        },
      ],
      additionalResolutions: [],
      quality: 90,
    },
  },
  upload: {
    config: {
      sizeLimit: 2097152, // 2MB in bytes
      mimeTypes: [
        "image/jpeg",
        "image/png",
        "image/gif",
        "image/webp",
        "image/avif",
      ],
      provider: "strapi-provider-cloudflare-r2",
      providerOptions: {
        accessKeyId: env("CF_ACCESS_KEY_ID"),
        secretAccessKey: env("CF_ACCESS_SECRET"),

        endpoint: env("CF_ENDPOINT"),
        params: {
          Bucket: env("CF_BUCKET"),
        },
        /**
         * Set this Option to store the CDN URL of your files and not the R2 endpoint URL in your DB.
         * Can be used in Cloudflare R2 with Domain-Access or Public URL: https://pub-<YOUR_PULIC_BUCKET_ID>.r2.dev
         * This option is required to upload files larger than 5MB, and is highly recommended to be set.
         * Check the cloudflare docs for the setup: https://developers.cloudflare.com/r2/data-access/public-buckets/#enable-public-access-for-your-bucket
         */
        // cloudflarePublicAccessUrl: env("CF_PUBLIC_ACCESS_URL"),
        /**
         * Sets if all assets should be uploaded in the root dir regardless the strapi folder.
         * It is useful because strapi sets folder names with numbers, not by user's input folder name
         * By default it is false
         */
        pool: false,
      },
      actionOptions: {
        upload: {},
        uploadStream: {},
        delete: {},
      },
    },
  },
});```
@nosovk
Copy link

nosovk commented Jun 20, 2024

It actually works with config like that:
/config/plugins.ts

import { Config as ImageOptimizerConfig } from 'strapi-plugin-image-optimizer/dist/server/models/config';

export default ({ env }) => ({
  upload: {
    config: {
      provider: 'strapi-provider-cloudflare-r2',
      providerOptions: {
        accessKeyId: env('CF_ACCESS_KEY_ID'),
        secretAccessKey: env('CF_ACCESS_SECRET'),
        /**
         * `https://<ACCOUNT_ID>.r2.cloudflarestorage.com`
         */
        endpoint: env('CF_ENDPOINT'),
        params: {
          Bucket: env('CF_BUCKET'),
        },
        /**
         * Set this Option to store the CDN URL of your files and not the R2 endpoint URL in your DB.
         * Can be used in Cloudflare R2 with Domain-Access or Public URL: https://pub-<YOUR_PULIC_BUCKET_ID>.r2.dev
         * This option is required to upload files larger than 5MB, and is highly recommended to be set.
         * Check the cloudflare docs for the setup: https://developers.cloudflare.com/r2/data-access/public-buckets/#enable-public-access-for-your-bucket
         */
        cloudflarePublicAccessUrl: env('CF_PUBLIC_ACCESS_URL'),
      },
      actionOptions: {
        upload: {},
        uploadStream: {},
        delete: {},
      },
    },
  },
  'image-optimizer': {
    enabled: true,
    config: {
      include: ['jpeg', 'jpg', 'png'],
      exclude: ['gif'],
      formats: ['original', 'webp', 'avif'],
      sizes: [
        {
          name: 'small',
          width: 500,
        },
        {
          name: 'medium',
          width: 750,
        },
        {
          name: 'large',
          width: 1920,
        },
      ],
      additionalResolutions: [2],
      quality: 90,
    } satisfies ImageOptimizerConfig,
  },
});

at https://statbet.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants