meteor add jimmiebtlr:slingshot-cloudinary
You'll need to create a upload preset in cloudinary. I belive the following options are needed.
- Mode: Signed
- UseFilename: true
- UniqueFilename: No
Slingshot.fileRestrictions('videos', {
allowedFileTypes: ['video/mp4'],
maxSize: 500000000,
});
Slingshot.createDirective('videos', Slingshot.Cloudinary, {
authorize() {
if (!this.userId) {
const message = 'Please login before posting files';
throw new Meteor.Error('Login Required', message);
}
return true;
},
key() {
return Meteor.uuid();
},
});
{
"CloudinaryCloudName": "cloud_name",
"CloudinarySecret": "secret",
"CloudinaryKey": "key",
"CloudinaryPreset": "preset"
}
Cloudinary allows a number of file upload options, as documented in their nodejs API. A few of these options are supported for now.
A tag name or an array with a list of tag names to assign to the uploaded image.
Slingshot.createDirective('videos', Slingshot.Cloudinary, {
authorize() {...},
key() {...},
tags: ['tag1', 'tag2']
});
An optional folder name where the uploaded resource will be stored. The public ID contains the full path of the uploaded resource, including the folder name.
Slingshot.createDirective('videos', Slingshot.Cloudinary, {
authorize() {...},
key() {...},
folder: myFolder
});
There is still work to be done. Pull requests welcome.
- Improve handling of video, image, and raw upload types.
- Check that public_id is checked using the signature.
- Implement all the file upload options supported by cloudinary