流星和Cloudinary - 回调未触发

时间:2017-01-01 21:11:37

标签: javascript meteor callback cloudinary

尝试将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);

  });

}

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题而且#34;解决了#34;它通过使用早期版本的包。我的.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);
    });
}