Upload media to digitalocean spaces using strapi v4

Hi! Do you have MIME Compatibility issues?
I published this post days ago, but I haven’t found a solution yet:

Actually i am ussing strapi-provider-upload-dos which seems to be more updated for strapi v4

Hi @Bipolab,

haven’t had any MIME issues so far and the media library works just fine. Where’re you uploading the files? In the administrator panel or via api?
I’m just using the media library by now.

I am using the administrator panel.
The video is uploaded and saved without problems in spaces. The problem is in Strapi’s preview. I don’t know if there is anything else to configure in the middleware.js file

as of today both strapi-provider-upload-do and strapi-provider-upload-dos wont work… always getting invalid enpoint: undefined error when trying to deploy to DigitalOcean. (using Strapi 4.1.6 btw) nobody maintains these plugins been stuck for 5 days now… already considering other upload providers because of this issue

It works fine just for the uploading but we face issue while getting the images and those issues are permession issue we cant see the images in the media

have you find any other plugin

If somebody facing this issue please use cloudinary

Hi,
just wondering where do you store these env variables (like DO_SPACE_ACCESS_KEY): in your .env file and commit this file to github as well? or store them in DigitalOcean platform inside App level or component level env…

Looking forward to your reply. Thanks in advance.

Hi @Amy_Li ,
pushing .env files is considered a bad practice. I’m storing the env variables in the App-Level Environment Variables on DO.

I am facing the same issue with video preview.

Using strapi-provider-upload-dos - npm this plugin.

Does anyone mange to solve this issue?

1 Like

SOLVED:

Digital Ocean is using AWS S3 to store media, so there is no need to use the strapi-provider-upload-do plugin. Instead, install the official @strapi/provider-upload-aws-s3 plugin and configure your plugins.js file like this.

This also enables the uploadStream option with is needed if you want to change e.g. the default Strapi Logo.

upload: {
    config: {
      provider: 'aws-s3',
      providerOptions: {
        accessKeyId: env('DO_SPACE_ACCESS_KEY'),
        secretAccessKey: env('DO_SPACE_SECRET_KEY'),
        endpoint: env('DO_SPACE_ENDPOINT'),
        params: {
          Bucket: env('DO_SPACE_BUCKET'),
        },
      },
      actionOptions: {
        upload: {},
        uploadStream: {},
        delete: {},
      },
    },
  },

Then update your middleware.js, too

module.exports = [
  'strapi::errors',
  {
    name: 'strapi::security',
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          'connect-src': ["'self'", 'https:'],
          'img-src': [
            "'self'",
            'data:',
            'blob:',
            'dl.airtable.com',
            '*.digitaloceanspaces.com',
          ],
          'media-src': [
            "'self'",
            'data:',
            'blob:',
            'dl.airtable.com',
            '*.digitaloceanspaces.com',
          ],
          upgradeInsecureRequests: null,
        },
      },
    },
  },
  'strapi::cors',
  'strapi::poweredBy',
  'strapi::logger',
  'strapi::query',
  'strapi::body',
  'strapi::session',
  'strapi::favicon',
  'strapi::public',
];

And finally, to enable video preview you need to configure CORS at your DigitalOcean account at your space. Simply click on “add” and enter “*” for Origin.

Thanks. but the video preview did not work.

  1. I cannot select this option inside content manager when selecting media. so had to duplicated video.
  2. Clicking on edit button does not show preview.

It seems that the URL is stripped. its starts with fra.digitaloceanspaces.com instead of https://fra.digitaloceanspaces.com.
The images are starting with https but the video URL not.

@Bipolab : Did you manage to solve the issue ?

Did you check your console log errors where the video preview wasn’t shown?

Unfortunately, there are no errors.

image

I tried your configuration. but it doesn’t upload anything. i have the env in app level environment vars and set CORS of the bucket to *

plugin.js

module.exports = ({env}) => ({
    upload: {
        config: {
            provider: 'aws-s3',
            providerOptions: {
                accessKeyId: env('DO_SPACE_ACCESS_KEY'),
                secretAccessKey: env('DO_SPACE_SECRET_KEY'),
                endpoint: env('DO_SPACE_ENDPOINT'),
                params: {
                    Bucket: env('DO_SPACE_BUCKET'),
                },
            },
            actionOptions: {
                upload: {},
                uploadStream: {},
                delete: {},
            },
        },
    },
})

middleware.js

module.exports = [
  'strapi::errors',
  {
    name: 'strapi::security',
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          'connect-src': ["'self'", 'https:'],
          'img-src': [
            "'self'",
            'data:',
            'blob:',
            'dl.airtable.com',
            '*.digitaloceanspaces.com',
          ],
          'media-src': [
            "'self'",
            'data:',
            'blob:',
            'dl.airtable.com',
            '*.digitaloceanspaces.com',
          ],
          upgradeInsecureRequests: null,
        },
      },
    },
  },
  'strapi::cors',
  'strapi::poweredBy',
  'strapi::logger',
  'strapi::query',
  'strapi::body',
  'strapi::session',
  'strapi::favicon',
  'strapi::public',
];

it still uploads everything in the upload folder and not in our DO space. What did i get wrong?

Why are you using the S3 provider for Digital Ocean :thinking:

because thefrontend mentioned that it is possible. and in the docs is clearly stated, that one can use it with s3 compatible services

Did you get any error in your server logs? Does the upload folder show preview images?

no errors - i get preview images and everything is located in the /upload/ folder