msoler75 / strapi-provider-upload-multiple-provider

Allow multiple upload providers in strapi
GNU General Public License v3.0
7 stars 11 forks source link

Strapi Upload Multiple Provider

Allow multiple upload providers in strapi (v3)

The selection of which provider to use is determined by a selectProvider function in settings with file information. Each provider is identified by keyString.

Each provider plugin need to be installed.

Installation

npm i strapi-provider-upload-multiple-provider

Use

config/plugins.js:

upload: {
  provider: "multiple-provider",
  providerOptions: {
    selectProvider(file) {
      // return some key string
    },
    providers: {
      'key1' : {
        provider: #providerName#,
        options: #providerOptions#
      },
      'key2' : {
        provider: #providerName#,
        options: #providerOptions#
      },
      ...
    }  
  }  
}

A more complete example:

config/plugins.js:

upload: {
  provider: "multiple-provider",
  providerOptions: {
    selectProvider(file) {
      if(file.name.match(/\.pdf$/))
        return 'documents'
      else if(file.name.match(/\.(jpe?g|png|webp|svg)$/))
        return 'images'
      else
        return 'default'
    },
    providers: {
      'default' : {
        provider: 'local',
      },
      'images' : {
         provider: 'google-cloud-storage',
         options: { 
           bucketName: 'mybucketimages',
           publicFiles: true,
           uniform: true,
           basePath: "",
        }
      },
      'documents': {
         provider: 'google-cloud-storage',
         options: {    
           bucketName: 'mybucketdocuments',
           publicFiles: true,
           uniform: true,
           basePath: "",
        }
      }
    }  
  }  
}