trieb-work / strapi-provider-cloudflare-r2

Official strapi provider to use the Cloudflare R2 object storage
https://market.strapi.io/providers/strapi-provider-cloudflare-r2
Other
16 stars 7 forks source link

Invalid bucket response #20

Open lintoncaldecott opened 5 months ago

lintoncaldecott commented 5 months ago

I am using the very simplest configuration according to the docs at https://market.strapi.io/providers/strapi-provider-cloudflare-r2 My configuration looks like this;

export default ({ env }) => ({
  upload: {
    config: {
      provider: 'strapi-provider-cloudflare-r2',
      providerOptions: {
        accessKeyId: env('CF_ACCESS_KEY_ID'),
        secretAccessKey: env('CF_ACCESS_SECRET'),
        endpoint: env('CF_ENDPOINT'),
        params: {
          Bucket: 'resources',
        },
        cloudflarePublicAccessUrl: env('CF_PUBLIC_ACCESS_URL'),
      },
      actionOptions: {
        upload: {},
        uploadStream: {},
        delete: {},
      },
    },
  },
});

A 1.8MB image upload fails with the response

[2024-05-08 09:07:40.476] error: The specified bucket does not exist. NoSuchBucket: The specified bucket does not exist.

My environment variables look like this

CF_ACCESS_KEY_ID=<redacted>
CF_ACCESS_SECRET=<redacted>
CF_PUBLIC_ACCESS_URL=https://pub-<redacted>.r2.dev
CF_BUCKET=resources
CF_ENDPOINT=https://<account-id>.r2.cloudflarestorage.com

I could say I copy and pasted my bucket name here, but I have quadruple checked the bucket 'resources' exists in my cloudflare R2 console.

lintoncaldecott commented 4 months ago

Is there anyone able to provide feedback for this?

JannikZed commented 4 months ago
upload: {
            config: {
                provider: 'strapi-provider-cloudflare-r2',
                providerOptions: {
                    accessKeyId: env('CF_ACCESS_KEY_ID'),
                    secretAccessKey: env('CF_SECRET_ACCESS_KEY'),
                    /**
                     * `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: {},
                },
            },
        },

@lintoncaldecott I'm not sure about the public access URL you are using - maybe that is the problem. We used a real one here: CF_PUBLIC_ACCESS_URL=https://static-dev.ch-source.de could you try that one out?

lintoncaldecott commented 4 months ago

@JannikZed Just tried it now, I get the same error [2024-05-24 14:04:48.857] error: The specified bucket does not exist. NoSuchBucket: The specified bucket does not exist.

tilman commented 4 months ago

I'm unable to reproduce this. Have you tried to 'hardcode' the variables in the config file and got it working with it? My first guess would be that bucket env variables are not correctly set. Other reason could be that you have some old AWS_... env variables set which are conflicting with this plugin as mentioned in the readme.

tilman commented 4 months ago

.