【发布时间】:2017-05-16 02:28:36
【问题描述】:
尝试将 Cloudinary 添加到我的 Meteor 应用程序中。
图像未进入 Cloudinary 媒体库,上传函数回调未触发。我知道以前有过问题,但我所做的似乎无济于事:
https://github.com/Lepozepo/cloudinary/issues/21
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