The situation: Im implementing image upload as profile pics on Meteor app using lepozepo:cloudinary package. So each user has 1 profile image. Uploading a new one will replace the photo. Similarly, deleting it will remove the only uploaded picture.
And so my questions are:
- Do I need to have a Collection to store the images? I prefer to upload to cloud and get URL to display it based on userId.
- Once picture is uploaded, how to I have a {{#if image}} then display uploaded pic, if not show default pic?
- I think the upload stacks on and on. IS there any way I can specify maximim upload of 1 image. If upload another, then it will replace the existing?
- How do i then only display the latest uploaded image?
The codes. ** config.js is set up on both server and client.
1) profile.js
Template.profile.events({
'submit form': function(e, t) {
e.preventDefault();
var files = [];
var file = $('#userimage')[0].files[0];
files.push(file);
console.log(files);
Cloudinary._upload(files[0], {}, function(err, res) {
if (err){
console.log("Error: " + err);
} else {
console.log("Success :" + res);
}
});
}
});
2) profile.html
<form>
<input type="file" id="userimage" name="userimage" class='upload_field cloudinary_fileupload' />
<div class="progress_bar" style='background-color: red, height: 20px'>
<div class='thumbnails'></div>
<button type="submit"> Upload </button>
<button type="delete"> Clear </button>
</form>