【问题标题】:Meteor and Cloudinary - Callback not firingMeteor and Cloudinary - 回调未触发
【发布时间】:2017-05-16 02:28:36
【问题描述】:

尝试将 Cloudinary 添加到我的 Meteor 应用程序中。

图像未进入 Cloudinary 媒体库,上传函数回调未触发。我知道以前有过问题,但我所做的似乎无济于事:

https://github.com/Lepozepo/cloudinary/issues/21

Meteor: Cloudinary

How to integrate Cloudinary with Meteor

Template.commentSubmit.events({
    'submit form': function(e, template) {
    e.preventDefault();

    var image = Session.get('photo'); // get image from mdg:camera
    //console.log(image);

    Cloudinary.upload(image, function(err, res) {
      if (err){
        console.log("Error: " + err);
        return;
      }
      console.log("Success: " + res);
    });

// code adding comment and image to mongodb

});

服务器:

Cloudinary.config({
  cloud_name: '****',
  api_key: '****',
  api_secret: '*****'
});

客户:

$.cloudinary.config({
  cloud_name: "******"
});

如果我手动将图像上传到 Cloudinary 仪表板,它会显示图像没有问题。使用最新版本的 Meteor 和 lepozepo:cloudinary

任何和所有的帮助/建议表示赞赏! :)

更新 - 得到它的工作:

var image = Session.get('photo');

if(image){ // check if post also includes image
  var files = [];
  files.push(dataURLtoBlob(image));

  let options = {
    folder: "app",
    image_metadata: true
  };

  var imageURL = ""; // loading gif

  Cloudinary.upload(files, options, function(err, res) {

      if (err){
        console.log("Error: " + err);
        return;
      }
      //console.log(res);
      imageURL = res.secure_url;
      //console.log(imageURL);

  });

}

【问题讨论】:

    标签: javascript meteor callback cloudinary


    【解决方案1】:

    我遇到了同样的问题,并通过使用早期版本的软件包“解决”了它。我的 .meteor/packages 现在有了这个:

    lepozepo:cloudinary@=4.2.2
    

    更新:

    我没有使用 mdg:camera 来获取数据,只是一个简单的输入。在桌面上,它显示文件浏览器。在 iOS 上,它显示“拍照/从库中选择”面板。 (它也适用于 Android)。

    代码如下所示:

    html:

    <input type="file" id="upload-image" class="file_bag" accept="image/*">
    

    js:

    'change #upload-image': function(event, template) {
        event.preventDefault();
    
        let files = $('input.file_bag')[0].files;
    
        let options = {
            folder: Meteor.userId(),
            image_metadata: true
        };
    
        Cloudinary.upload(files, options, function(error, result) {
            console.log(result.public_id);
        });
    }
    

    【讨论】:

    • 感谢 zim。我降级了 cloudinary 包。我现在收到此错误:
    • Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'. at functions.coffee:67 at Function._.each._.forEach (underscore.js?hash=cde485f…:152) 我尝试给它一个数组作为参数,并改用 _upload_file 函数,但没有运气。我想知道来自Session.get('photo'); 的数据是否是 cloudinary 函数的正确文件类型?
    • @sutebu,你试过用输入标签代替吗?我已经通过回答更新了我是如何做到的。
    • 谢谢@zim!让它与您的输入标签一起使用。这向我表明这不是其他问题,因此我探索了使用以下方法将我的 base64 imageURL 转换为 blob:stackoverflow.com/questions/23150333/… 效果很好! :)
    猜你喜欢
    • 2015-11-06
    • 2017-04-20
    • 2011-02-12
    • 2020-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-26
    相关资源
    最近更新 更多