Skip to content
This repository has been archived by the owner on Feb 23, 2019. It is now read-only.

Get metaContext in 'upload' and pass parameters to the directive key() #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,19 @@ Slingshot.Cloudinary = {
CloudinaryPreset: Meteor.settings.CloudinaryPreset,
}),

isImage(mime) {
return _.contains(['image/jpeg','image/jpg', 'image/png', 'image/svg', 'application/pdf'], mime);
// Determined by mime types 'image/*' and 'video/*'
resourceType(mimeType) {
const mimeSplit = mimeType.split('/');

if (_.contains(['image', 'video'], mimeSplit[0]))
return mimeSplit[0];
else
return 'raw';
},

isVideo(type) {
return _.contains(
['video/mp4'],
type
);
},

resourceType(type) {
return this.isImage(type)
? 'image'
: this.isVideo(type)
? 'video'
: 'raw';
},

upload: function upload(method, directive, file) {
upload: function upload(method, directive, file, meta) {
const { CloudinaryCloudName } = directive;
const publicId = directive.key();
const publicId = directive.key(method, file, meta);

// Cloudinary's node lib supplies most of what we need.
const cloudinarySign = this.cloudinarySign(publicId, directive, file);
Expand Down