Cloudinary

This package is used to cache a image already hosted online using Cloudinary. To upload a local image using Cloudinary check out the Forms Upload package instead.

Config

In your private settings:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
"cloudinary": {
"apiKey": "123foo",
"apiSecret": "456bar",
"formats": [
{
"name": "small",
"width": 180,
"height": 100}
, {
"name": "medium",
"width": 400,
"height": 250 }
]
},

makeCloudinary

You can enable Cloudinary caching on a collection using the makeCloudinary function:

1
2
3
4
import { Posts } from 'meteor/example-forum';
import { makeCloudinary } from 'meteor/vulcan:cloudinary';

makeCloudinary({collection: Posts, fieldName: 'thumbnailUrl'});

The collection option indicates which collection you want to use Cloudinary with, while the fieldName option indicates which field you want to cache (which should contain an image URL).

Note that at this time, you can only cache a single image field per collection.

Custom Fields

makeCloudinary will add the following custom fields to store image data:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[
{
fieldName: 'cloudinaryId',
fieldSchema: {
type: String,
optional: true,
canRead: ['guests'],
}
},
{
fieldName: 'cloudinaryUrls',
fieldSchema: {
type: Array,
optional: true,
canRead: ['guests'],
}
},
{
fieldName: 'cloudinaryUrls.$',
fieldSchema: {
type: Object,
blackbox: true,
optional: true
}
}
]

In addition, the cloudinaryUrl GraphQL-only field is also available as a shortcut to get a specific image format’s URL.

It optionally takes a format argument when used inside a GraphQL query or fragment, for example:

1
cloudinaryUrl(format: "small")

Callbacks

makeCloudinary will also add two callbacks on collection.new.sync and collection.edit.sync to cache your images.

Edit on GitHub