Lepozepo / cloudinary

MIT License
94 stars 42 forks source link

Callback function not firing #21

Open PCoetzeeDev opened 9 years ago

PCoetzeeDev commented 9 years ago

Hi,

Appologies if this is a silly question, I'm still new to meteor. I'm trying to use the basic uploader for now, but I can't seem to get the callback function to fire from spacebars?

Everything else seems ok, the photos are uploaded, reports on progress, etc. $.cloudinary and the local collection _cloudinary all seem fine.

Not quite sure what I'm missing here, maybe some syntax issues? Any help would be very much appreciated!

Lepozepo commented 9 years ago

Post the code so I can have a look :)

PCoetzeeDev commented 9 years ago

Sure

Method on server:

Meteor.methods({
        save_url:function(response){
            //console.log(response);
            console.log('Add '+response.upload_data+' to the id of '+response.context);
        }
});

In the view:

{{#c_upload_stream callback="save_url"}}
            <input type="file">
{{/c_upload_stream}}

{{#each c.uploading_images}}
            <p>{{percent_uploaded}}</p>
{{/each}}

I've also tried hooking into the local minimongo's after update with:

_cloudinary.after.update(function(user,file){
    if(file.percent_uploaded === 100 && !file.uploading){
        console.log(file);
    }
});

I then get the following error in console:

TypeError: Cannot read property 'update' of undefined
    at Template.posts-set.rendered (posts-set.js?8475729bfc469c2c4415c172c1d6866798d07328:12)
    at template.js:116
    at Function.Template._withTemplateInstanceFunc (template.js:437)
    at fireCallbacks (template.js:112)
    at null.<anonymous> (template.js:205)
    at view.js:104
    at Object.Blaze._withCurrentView (view.js:523)
    at view.js:103
    at Object.Tracker._runFlush (tracker.js:468)
    at onGlobalMessage (setimmediate.js:102)

Photos are showing up in my Cloudinary media library, but I just can't seem to get the data_id back. I need to save it to a collection.

Thanks for your help!

Lepozepo commented 9 years ago

That's strange that it doesn't work. I'll check for bugs as soon as I get a chance.

PCoetzeeDev commented 9 years ago

Thanks, really appreciate it!

One thing, when I query the local collection record, the uploading attribute is still set to true. Not sure if that helps in anyway.

DEfusion commented 9 years ago

+1

I tried both c_upload and c_upload_stream I get no errors in either client or the server however.

DEfusion commented 9 years ago

This anonymous function is never being called for me https://github.com/Lepozepo/cloudinary/blob/master/client/controllers.js#L54

DEfusion commented 9 years ago

Still poking at it but I've found something very weird, if I manually do Meteor.call('afterCloudinaryUpload') before doing an upload I get an error as expected as I've not provided a response. However after attempting an upload trying to call it manually again I get no errors and no output in the console.

Lepozepo commented 9 years ago

Hey! I'll take a look at it today. I've been busy closing one of my shops but now I'm in a sweet moment of "nothing else to do" WOOHOO!

DEfusion commented 9 years ago

Thanks @Lepozepo one last thing as I'm just heading out for a bit if you add this debugging into the server JS:

if(_.has(options,"callback")){
    console.log('calling callback');
    Meteor.call(options.callback,callback_options);
    console.log('called');
}

The first message is logged but the 2nd is never logged.

DEfusion commented 9 years ago

I really can't figure this out so for now I've removed the callback param from the tag and using the _cloudinary.after.update hook to then call my afterCloudinaryUpload method with the file. Doing that is working for me at the moment.

DEfusion commented 9 years ago

I've just experienced something similar in my own code, trying to do a Meteor.call() serverside from within a Meteor.call() is causing the first method called to fail silently. Don't know if this is a core meteor issue or something to do with packages installed.

DEfusion commented 9 years ago

I think I have it figured out for me. My app was started from the meteor boilerplate which includes the https://github.com/matteodem/meteor-easy-security package by default. That has rate limiting on calling methods.

Added an issue over there https://github.com/matteodem/meteor-easy-security/issues/20

PCoetzeeDev commented 9 years ago

That makes sense, I'm also using the boilerplate with easy-security module

Lepozepo commented 9 years ago

Wow, I don't think I would've figured that one out easily. After you remove easy security the package works?

DEfusion commented 9 years ago

I'm not actually using the c_upload_stream anymore but doing my own legwork (for various reasons) and then calling cloudinary_upload_stream with the data directly. But I imagine it would, a very simple test is to take a working app and add he easy-security package it instantly kills the ability for methods to then do Meteor.call() for me.

chandan-singh commented 9 years ago

Thanks DEfusion! I wasted my 2 hours just struggling to fix this issue before I saw your post.