Skip to content

Conversation

@bglidwell
Copy link
Contributor

@bglidwell bglidwell commented Jan 25, 2021

Supports options object in providerOptions which can contain any cloudinary upload/delete options

Linked Issues

#5069

What does it do?

Adds support for options in cloudinary plugin config

  upload: {
    provider: 'cloudinary',
    providerOptions: {
      cloud_name: env('CLOUDINARY_NAME'),
      api_key: env('CLOUDINARY_KEY'),
      api_secret: env('CLOUDINARY_SECRET'),
      options: {
        folder: env('CLOUDINARY_FOLDER')
      }
    },
  },

Why is it needed?

setting cloudinary options such as a default folder per environment

Related issue(s)/PR(s)

Let us know if this is related to any issue/pull request

Supports options object in providerOptions which can contain any cloudinary upload/delete options
@codecov
Copy link

codecov bot commented Jan 25, 2021

Codecov Report

Merging #9219 (1775794) into master (5d8f5fb) will increase coverage by 0.00%.
The diff coverage is 39.28%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #9219   +/-   ##
=======================================
  Coverage   34.64%   34.65%           
=======================================
  Files        1308     1308           
  Lines       14431    14452   +21     
  Branches     1432     1438    +6     
=======================================
+ Hits         5000     5008    +8     
- Misses       8517     8529   +12     
- Partials      914      915    +1     
Flag Coverage Δ
front 26.02% <6.25%> (-0.03%) ⬇️
unit 54.92% <83.33%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...nt-manager/admin/src/components/InputJSON/index.js 0.00% <0.00%> (ø)
...t-manager/admin/src/components/SelectMany/index.js 0.00% <ø> (ø)
...nt-manager/admin/src/components/SelectOne/index.js 0.00% <ø> (ø)
...anager/admin/src/components/SelectWrapper/index.js 0.00% <0.00%> (ø)
...in-content-manager/admin/src/translations/index.js 0.00% <0.00%> (ø)
...ntent-type-builder/admin/src/translations/index.js 0.00% <0.00%> (ø)
...trapi-plugin-email/admin/src/translations/index.js 0.00% <0.00%> (ø)
...rapi-plugin-upload/admin/src/translations/index.js 0.00% <0.00%> (ø)
...-users-permissions/admin/src/translations/index.js 0.00% <0.00%> (ø)
...strapi-plugin-upload/config/functions/bootstrap.js 60.97% <33.33%> (-3.13%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3f63902...ec69348. Read the comment docs.


module.exports = {
init(config) {
cloudinary.config(config);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the config here is the providerOptions you cannot access the options if they are set outside

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the requested change. This is tested working as submitted and was just the least invasive way to add the options. If desired, I could possibly split the upload and delete options out to their own key at the upload config level and pull them out separately?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misread the example config and thought the key was on the upload config level :)

The naming might be improved I think, options doesn't say much about where it is going to be used :)

make sure to also omit the key from the config you pass down to the cloudinary sdk too ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to any suggestions for naming.

As for the config object, would you be open to splitting the providerOptions object into another set of keys for providerOptions.cloudinaryConfig and perhaps something like providerOptions.cloudinaryOptions for the upload/delete options? It just makes the whole object split much more explicit rather than trying to omit a key from the unit function.

Thanks again for taking a look at this PR. This feature will really help my particular use case where I want to use one cloudinary account for both staging and production environments without mixing the files together in root directory (options allows me to specify a folder per environment in this case to keep things organized and separate)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid splitting for now as it will be a breaking change.

We could add another key next to the providerOptions that would be used to wrap the provider actions when we initialize it in the createProvider at packages/strapi-plugin-upload/config/functions/bootstrap.js

sth like:

const createProvider = ({ provider, providerOptions, actionOptions }) => {
  const providerInstance = require(`strapi-provider-upload-${provider}`).init(providerOptions);

    return Object.assign(Object.create(baseProvider), {
      ...providerInstance,
      upload(file, options = actionOptions.upload || {}) {
        return providerInstance.upload(file, options);
      },
      delete(file, options = actionOptions.delete || {}) {
        return providerInstance.delete(file, options);
      },
    });
};

with this config

upload: {
  provider: '',
  providerOptions: {},
  actionOptions: {
    upload: {},
    delete: {}
  }
}

This would make this work for any provider that wants to implement something with it. What do you think ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love it, and agree on the breaking change, I'll add that and submit shortly

@alexandrebodin alexandrebodin added source: core:upload Source is core/upload package issue: enhancement Issue suggesting an enhancement to an existing feature labels Jan 26, 2021
used to initialize upload/delete custom options which can be passed to a provider's upload/delete function
added actionOptions description with link to available cloudinary upload/delete options
@bglidwell bglidwell changed the title add support for config.options to cloudinary upload and delete functions add support for actionOptions for provider upload and delete functions Jan 27, 2021
Copy link
Member

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last thing required :)

Add actionsOptions default value ({}) in the plugin /config/config.json

@alexandrebodin
Copy link
Member

Hey @bglidwell would you be willing to add this to some of the documentation on the doc repo ? @derrickmehaffy might give you good pointers on where to add it ;)

Copy link
Member

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@alexandrebodin alexandrebodin added this to the 3.4.6 milestone Jan 28, 2021
@alexandrebodin alexandrebodin merged commit b77b064 into strapi:master Jan 28, 2021
@derrickmehaffy
Copy link
Member

This pull request has been mentioned on Strapi Community Forum. There might be relevant details there:

https://forum.strapi.io/t/strapi-cloudinary-upload-presets-help/1282/7

@derrickmehaffy
Copy link
Member

This pull request has been mentioned on Strapi Community Forum. There might be relevant details there:

https://forum.strapi.io/t/new-release-strapi-v3-4-6/2631/1

@abdonrd
Copy link
Contributor

abdonrd commented Feb 5, 2021

Is there any possibility to configure this at the model attribute level?
I would like to be able to sort the images by folders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

issue: enhancement Issue suggesting an enhancement to an existing feature source: core:upload Source is core/upload package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants