Fork
This package based on lepozepo:cloudinary. It has no Blaze template helpers and templating-package dependency. In addition, the npm dependencies are updated.
Cloudinary Image/File Uploader
Cloudinary provides a simple way for uploading files to Cloudinary, which in turn can be set up to sync with your Amazon S3 service. This is useful for uploading and actively manipulating images and files that you want accesible to the public. Cloudinary is built on Cloudinary (NPM) and Cloudinary (JS). Installing this package will make Cloudinary available server-side and $.cloudinary available client-side.
Installation
$ meteor add lmachens:cloudinary
How to upload
Step 1
Configure your Cloudinary Credentials and Delete Authorization Rules. SERVER SIDE AND CLIENT SIDE.
1// SERVER 2Cloudinary.config({ 3 cloud_name: 'cloud_name', 4 api_key: '1237419', 5 api_secret: 'asdf24adsfjk' 6}); 7 8// Rules are all optional 9Cloudinary.rules.delete = () => { 10 if (this.userId === "my_user_id") { 11 // The rule must return true to pass validation, if you do not set a rule, the validation will always pass 12 } 13 this.public_id; // The public_id that is being deleted 14}; 15 16Cloudinary.rules.signature = () => { // This one checks whether the user is allowed to upload or not 17 if (this.userId === "my_user_id") { 18 // The rule must return true to pass validation, if you do not set a rule, the validation will always pass 19 } 20}; 21 22Cloudinary.rules.private_resource = () => { 23 if (this.userId === "my_user_id") { 24 // The rule must return true to pass validation, if you do not set a rule, the validation will always pass 25 } 26}; 27 28Cloudinary.rules.download_url = () => { 29 if (this.userId === "my_user_id") { 30 // The rule must return true to pass validation, if you do not set a rule, the validation will always pass 31 } 32}; 33 34// CLIENT 35$.cloudinary.config({ 36 cloud_name: "cloud_name" 37}); 38
Step 2
Wire up your input[type="file"]. CLIENT SIDE.
1Cloudinary.upload(event.currentTarget.files, { 2 folder: "secret", // optional parameters described in http://cloudinary.com/documentation/upload_images#remote_upload 3 type: "private", // optional: makes the image accessible only via a signed url. The signed url is available publicly for 1 hour. 4 (err, res) => { // optional callback, you can catch with the Cloudinary collection as well 5 console.log(`Upload Error: ${err}`); 6 console.log(`Upload Result: ${res}`); 7 } 8}); 9
How to protect your images
You will need an Advanced Cloudinary account before you can make your images fully private. Once you have your account you can do one of 2 things:
- Set up a custom CNAME and ask Cloudinary to whitelist your domains via email
- Upload
type:"authenticated"images and request them via cloudinary's authentication scheme (I'm working on simplifying this part)
Compatibility
You can use the collection-hooks package to hook up to the offline collection Cloudinary.collection.
If you are using the browser-policy package, don't forget to allow images from cloudinary to load on your webapp by using BrowserPolicy.content.allowImageOrigin("res.cloudinary.com")
Here are all the transformations you can apply: http://cloudinary.com/documentation/image_transformations#reference
Cordova Android Bug with Meteor 1.2+
Due to a bug in the Cordova Android version that is used with Meteor 1.2, you will need to add the following to your mobile-config.js or you will have problems with this package on Android devices:
1App.accessRule("blob:*");
How to delete from Cloudinary
Just pass the public_id of the image or file through this function (security features pending). It will return an object with a list of the images deleted as a result.
1Cloudinary.delete(response.public_id, (err,res) => { 2 console.log(`Upload Error: ${err}`); 3 console.log(`Upload Result: ${res}`); 4});
How to generate a downloadable link
1Meteor.call("c.get_download_url", public_id, (err,d ownload_url) => { 2 console.log(`Upload Error: ${err}`); 3 console.log(download_url); 4});
API
-
Cloudinary.config(options) (SERVER) required:
- cloud_name: Name of your cloud
- api_key: Your Cloudinary API Key
- api_secret: Your Cloudinary API Secret
-
Cloudinary.rules (SERVER) optional: This is a javascript object of rules as functions
- Cloudinary.rules.delete: Checks whether deleting a resource is allowed. Return true to allow the action.
- Cloudinary.rules.signature: Checks whether uploading a resource is allowed. Return true to allow the action.
- Cloudinary.rules.private_resource: Checks whether getting a private resource is allowed. Return true to allow the action.
- Cloudinary.rules.download_url: Checks whether fetching a download link for a resource is allowed. Return true to allow the action.
Helpers
-
Cloudinary.url(public_id, options): Generates a url
- public_id: The public ID returned after uploading a resource
- options: A set of transformations described here http://cloudinary.com/documentation/image_transformations#reference
-
Cloudinary.private_url(public_id, options): Generates a signed url
- public_id: The public ID returned after uploading a resource
- options: A set of transformations described here http://cloudinary.com/documentation/image_transformations#reference
-
Cloudinary.expiring_url(public_id): Generates a url that will expire in 1 hour, does not take any transformations
- public_id: The public ID returned after uploading a resource
Notes
A security filter is missing, I know how I want it to work I just haven't had the time to build it. Enjoy the new version!