Giter Site home page Giter Site logo

verdecircle / strapi-provider-upload-cloudinary-folderoptions Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 3.0 12 KB

an extension of the strapi-provider-upload-cloudinary that allows for a default_folder option in the config as well as using the file name to define folder structure.

Home Page: https://www.npmjs.com/package/strapi-provider-upload-cloudinary-folderoptions

License: Other

JavaScript 100.00%

strapi-provider-upload-cloudinary-folderoptions's Introduction

strapi-provider-upload-cloudinary-folderoptions

This is an extended version of strapi-provider-upload-cloudinary

Configurations

Your configuration is passed down to the cloudinary configuration. (e.g: cloudinary.config(config)). You can see the complete list of options here

See the using a provider documentation for information on installing and using a provider. And see the environment variables for setting and using environment variables in your configs.

Example default_folder option has been added to the config to allow for uploading to a specific cloudinary folder by default. The file name can also be used to specify a folder structure that remains under the default_folder option or overrides the default_folder options.

For example:

  • example_app.png could be uploaded to /[default_folder]/logos/apps cloudinary folder by having a default_folder option set and changing the file name to logos/apps/example_app.png

  • If you want to override the default_folder options at the time of upload, change the file name to /logos/apps/example_app.png. This would upload the file under a cloudinary folder structure of /logos/apps instead of /[default_folder]/logos/apps

While Cloudinary can handle all the image size/cropping/quality/etc for you so that you don't have to turn on the "Enable responsive friendly upload" on Strapi, this will also take into consideration the different default sizing Strapi performs and place them in subfolder accordingly (e.g. thumbnail, small, medium, large)

Starting Cloudinary Starting Cloudinary

Upload files to root by adding /logos/apps/ to the file name Upload Asset in Strapi with desired folder strcuture

And the result is... New Folder in Cloudinary root New Folder in Cloudinary root

Files in directory structure specified Files in directory structure specified ^^^ In this case, we have "Enable responsive friendly upload" set to on in Strapi>Settings>Media Library

Strapi Media Library Settings

Upload files using the default_folder option AND even adding your own folder structure Strapi Asset Upload default_folder & additional folder structure

And the result is... default_folder (which is set in .env file) created on cloudinary root with file specific sub folders as well default_folder option

Upload to default_folder only Strapi Upload to default_folder only

Files placed in root of default_folder on Cloudinary Root of default_folder

./config/plugins.js

module.exports = ({ env }) => ({
  // ...
  upload: {
    provider: 'cloudinary-folderoptions',
    providerOptions: {
      cloud_name: env('CLOUDINARY_NAME'),
      api_key: env('CLOUDINARY_KEY'),
      api_secret: env('CLOUDINARY_SECRET'),
      default_folder: env('CLOUDINARY_DEFAULT_FOLDER'),
    },
  },
  // ...
});

Resources

Links

strapi-provider-upload-cloudinary-folderoptions's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

strapi-provider-upload-cloudinary-folderoptions's Issues

why a distinct repository ?

Hi !

Thank you for your work !

I was wondering, why a single feature would need a distinct project ?

Using the main package (strapi-provider-upload-cloudinary) like so does exactly the same thing, is additional value to using this package ?

module.exports = ({ env }) => ({
  upload: {
    provider: 'cloudinary',
    providerOptions: {
      cloud_name: env('CLOUDINARY_NAME'),
      api_key: env('CLOUDINARY_KEY'),
      api_secret: env('CLOUDINARY_SECRET'),
    },
    actionOptions: {
      upload: {
        folder: env('NODE_ENV'),
      },
      delete: {},
    },
  },
});

Cheers

support for eager async preview urls (big videos)

Hi awesome tool! i love it. realized for large videos preview url gif you try to generate gets 400'd due to automatic on the fly generation only works for file sizes 40mb and below. need to supply eager_async: true, so adding this slight change to your code would support it:

In the code put

if (image.resource_type === 'video') {
  if (image.eager?.length) {
    file.previewUrl = image.eager[0].secure_url;
  } else {
    file.previewUrl = cloudinary.url(`${image.public_id}.gif`, {
      video_sampling: 6,
      delay: 200,
      width: 250,
      crop: 'scale',
      resource_type: 'video',
    });
  }
}

example setting:

    actionOptions: {
          upload: {
            eager: [
              { video_sampling: 6,
                delay: 200,
                width: 250,
                crop: 'scale',
                resource_type: 'video',
                fetch_format: 'gif',
                format: 'gif',
              }
            ],
            eager_async: true,
          },
        }
      },
      ```
      
      

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.