Cloudinary Instance

This module globally injects $cloudinary instance. You can access it anywhere using this.$cloudinary (within a component), or context.$cloudinary (for plugins, asyncData, fetch, nuxtServerInit and middleware).

From v1.0.0+, this instance is also available when useComponent is set to true in nuxt.config.js.

If you are using v0.0.11 and older, please check out Deprecated API instead.

$cloudinary

v1.0.0+
  • Returns an CloudinaryApi instance designated according the setup options.

Below are the available properties and methods of the returned object.

Properties

image

v1.0.0+
  • Returns an Object with methods designated for images.

See Image URLs and Tags for the full list of available methods.

video

v1.0.0+
  • Returns an Object with methods designated for videos.

See Video URLs and Tags for the full list of available methods.

Methods

upload(file, options, callback)

v1.0.0+
  • file
    • Type: String
    • required
    • Path to the target asset file for uploading
  • options
    • Type: Object
    • Configuration options to apply to the target asset during uploading to Cloudinary.
  • callback
    • Type: Function
    • A callback method to trigger once the upload is completed. It is not needed if you are using ES6 async/await or Promise API.
  • Returns: a Promise<Asset | Error>

Upload the target asset file to Cloudinary, in a secured (server-side) or non-secure (client-side), depending on the use case.

See Upload assets for the full specs and examples.

const instance = this.$cloudinary
                .upload('my-target-file-path', {
                  public_id: 'Example'
                })

You can pre-generate transformation for uploading asset by passing the desired transformations to options.eager.

See Optional parameters for the full list of available supported properties for options.

explicit(publicId, options)

v1.0.0+

This method is only available on server-side. Calling it on client-side during run time will cause error.

  • publicId
    • Type: String
    • required
    • Path to the original asset stored in Cloudinary.
  • options
    • Type: Object
    • options.type is required.

Some common accepted values for type are upload, private, authenticated, fetch, and multi. See Cloudinary delivery types for full list of available values.

Returns an Object contains information of found asset, or null if the target asset doesn't exist.

const instance = this.$cloudinary
                .explicit('my-target-public-id', {
                  type: 'upload'
                })

You can pre-generate transformation for existed asset by passing the desired transformations to options.eager.

See Optional parameters for the full list of available supported properties for options.

config(options)

  • options
    • Type: Object
    • Configuration options for Cloudinary.
  • Returns a new CloudinaryApi instance for chaining v1.0.0+

Create a new CloudinaryApi instance from the default setup defined in nuxt.config.js and the passed options.

const instance = this.$cloudinary
                .config({
                  cloudName: 'your-new-cloud-name'
                })

See Cloudinary options for the full list of available options.