strapi-provider-upload-do-virtuali

3.8.9 • Public • Published

Strapi Upload Provider for Digital Ocean Spaces

This provider will upload to the space using the AWS S3 API.

Parameters

  • key : Space access key
  • secret : Space access secret
  • endpoint : Base URL of the space (e.g. fra.digitaloceanspaces.com)
  • space : Name of the space in the Digital Ocean panel.
  • directory : Name of the sub-directory you want to store your files in. (Optionnal - e.g. /example)
  • cdn : CDN Endpoint - URL of the cdn of the space (Optionnal - e.g. cdn.example.com)

How to use

  1. Install this package
npm i strapi-provider-upload-do
yarn add strapi-provider-upload-do
pnpm add strapi-provider-upload-do
  1. Create or update config in ./config/plugins.js with content
module.exports = ({env}) => ({
  // ...
  upload: {
    config: {
      provider: "strapi-provider-upload-do-virtuali",
      providerOptions: {
        key: env('DO_SPACE_ACCESS_KEY'),
        secret: env('DO_SPACE_SECRET_KEY'),
        endpoint: env('DO_SPACE_ENDPOINT'),
        space: env('DO_SPACE_BUCKET'),
        directory: env('DO_SPACE_DIRECTORY'), // default destination directory
        cdn: env('DO_SPACE_CDN'),
        folders: [{folderName: 'courses', acl: 'private'}, {folderName: 'members', acl: 'private'}],
        acl: 'public-read', // default ACL
      },
      actionOptions: {
        upload: {},
        uploadStream: {},
        delete: {},
      },
    },
  }, 
  // ...
})
  1. Create .env and add provide Digital Ocean config.
DO_SPACE_ACCESS_KEY=
DO_SPACE_SECRET_KEY=
DO_SPACE_ENDPOINT=
DO_SPACE_BUCKET=
DO_SPACE_DIRECTORY=
DO_SPACE_CDN=

with values obtained from tutorial:

https://www.digitalocean.com/community/tutorials/how-to-create-a-digitalocean-space-and-api-key

Parameter DO_SPACE_DIRECTORY and DO_SPACE_CDN is optional and you can ommit them both in .env and settings.

Configuration to displiay thumbnails in strapi media library

Create or update config in ./config/middlewares.js with content

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

Changes

  • If the directory property value is undefined files will be uploaded to the root of the space.
  • If the acl property is undefines files will be set a public 'public-read'.
  • This plugin will check if the name has this format mainfolder_subfolder_fileName.ext the file will be uploaded to mainfolder/subfolder/fileName.ext under the space root. The main folder is validated agains folders array to obtain the acl of the file.
  • This plugin is comppatible with strapi v4.x.
  • Was added method to download the file from DO and return it as ReadStream

Resources

Links

Contributors

Package Sidebar

Install

npm i strapi-provider-upload-do-virtuali

Homepage

strapi.io

Weekly Downloads

1

Version

3.8.9

License

MIT

Unpacked Size

12.4 kB

Total Files

5

Last publish

Collaborators

  • gajupo