如何检索 Cloudinary photoid?
How to retrieve Cloudinary photoid?
Cloudinary 有一个 photo_id 是在照片上传后分配的,但我不知道如何检索它。我正在使用流星。下面是用户上传照片的代码。
Template.userProfile.events({
'submit form': function(e, t) {
e.preventDefault();
var files = [];
var file = $('#userimage')[0].files[0];
files.push(file);
Meteor.call('uploadPhoto', Meteor.userId(), "test")
Cloudinary.upload(files, function(err, res) {
console.log("Upload Error: " + err);
console.log("Upload Result: " + res);
});
},
});
我想使用下面的代码将 photoId 或 url 设置为用户 JSON 对象的字段。
uploadPhoto: function(userId, photoId) {
Meteor.users.update(userId, {
$set: {photoId: photoId}
});
}
当我测试 res:
var i = [];
Cloudinary.upload(files, function(err, res) {
i.push(res.public_id)
console.log(i)
});
console.log(i)
console.log只是显示一个空数组。
Below is an example of an upload's result:
{ public_id: '4srvcynxrf5j87niqcx6w',
version: 1340625837,
signature: '01234567890abcdef01234567890abcdef012345',
width: 200,
height: 200,
format: 'jpg',
resource_type: 'image',
// ...
}
尝试在文件和函数之间添加 {}。
Cloudinary.upload(files, {}, function(err, res) {
....
});
Cloudinary 有一个 photo_id 是在照片上传后分配的,但我不知道如何检索它。我正在使用流星。下面是用户上传照片的代码。
Template.userProfile.events({
'submit form': function(e, t) {
e.preventDefault();
var files = [];
var file = $('#userimage')[0].files[0];
files.push(file);
Meteor.call('uploadPhoto', Meteor.userId(), "test")
Cloudinary.upload(files, function(err, res) {
console.log("Upload Error: " + err);
console.log("Upload Result: " + res);
});
},
});
我想使用下面的代码将 photoId 或 url 设置为用户 JSON 对象的字段。
uploadPhoto: function(userId, photoId) {
Meteor.users.update(userId, {
$set: {photoId: photoId}
});
}
当我测试 res:
var i = [];
Cloudinary.upload(files, function(err, res) {
i.push(res.public_id)
console.log(i)
});
console.log(i)
console.log只是显示一个空数组。
Below is an example of an upload's result:
{ public_id: '4srvcynxrf5j87niqcx6w',
version: 1340625837,
signature: '01234567890abcdef01234567890abcdef012345',
width: 200,
height: 200,
format: 'jpg',
resource_type: 'image',
// ...
}
尝试在文件和函数之间添加 {}。
Cloudinary.upload(files, {}, function(err, res) {
....
});