https://github.com/baskeboler/mongoose-crate-cloudinary
cloudinary storage provider for mongoose-crate
https://github.com/baskeboler/mongoose-crate-cloudinary
Last synced: 28 days ago
JSON representation
cloudinary storage provider for mongoose-crate
- Host: GitHub
- URL: https://github.com/baskeboler/mongoose-crate-cloudinary
- Owner: baskeboler
- Created: 2016-07-01T08:57:43.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-04T20:13:55.000Z (almost 10 years ago)
- Last Synced: 2025-10-26T04:18:52.574Z (8 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mongoose-crate-cloudinary
cloudinary storage provider for mongoose-crate
## installation
`$> npm install mongoose-crate-cloudinary --save`
## usage
```javascript
var crate = require('mongoose-crate'),
CloudinaryStorageProvider = require('mongoose-crate-cloudinary');
// Only necessary if CLOUDINARY_URL env var not set.
// Else instantiate with empty config object.
var storageProvider = new CloudinaryStorageProvider({
cloud_name: 'YOUR CLOUD NAME',
api_key: 'YOUR API KEY',
api_secret: 'YOUR API SECRET'
});
// Use in mongoose schema ..
PictureSchema.plugin(crate, {
storage: storageProvider,
fields: {
image: {}
}
});
```
the cloudinary image `public_id` will be saved in the url field of the image, for example:
```javascript
var cloudinary = require('cloudinary');
var pic = new Picture({
caption: 'image caption',
otherField: 'blablabla'
});
pic.attach('image', '/path/to/image', (err) => {
if (err) handleError(err);
else {
// image id is in pic.image.url
var originalImageUrl = cloudinary.url(pic.image.url,{});
var croppedImageUrl = cloudinary.url(pic.image.url, {
width: 100,
height: 150,
crop: 'fill'
});
var croppedImageSecureUrl = cloudinary.url(pic.image.url, {
secure: true,
width: 100,
height: 150,
crop: 'fill'
});
}
});
```