Skip to content

Instantly share code, notes, and snippets.

@sylido
Created May 28, 2014 00:14
Show Gist options
  • Save sylido/51611949b402d2177dc9 to your computer and use it in GitHub Desktop.
Save sylido/51611949b402d2177dc9 to your computer and use it in GitHub Desktop.
test js file
// rename to testProd.js
Router.configure({
layoutTemplate : "layoutTemplate"
});
Router.map(function() {
this.route('/', {
template: "blobImage"
});
});
ImagesFS = new CollectionFS("images", { autopublish: true });
ImagesFS.filter({
allow: {
contentTypes: ["image/*"],
extensions: ["png", "jpg", "jpeg", "gif"]
},
maxSize : 5242880 // 5 mb
});
ImagesFS.allow({
insert: function(userId, file) {
return true;
},
update: function(userId, files, fields, modifier) {
return true;
},
remove: function(userId, files) {
return true;
}
});
if (Meteor.isClient) {
Template.queueControl.events({
'change .fileUploader': function (e) {
var files = e.target.files;
for (var i = 0, f; f = files[i]; i++) {
ImagesFS.storeFile(f);
}
}
});
// Template.fileTable.file = function() {
// //show all files that have been published to the client, with most recently uploaded first
// return ImagesFS.find({}, { sort: { uploadDate:-1 } });
// };
// client
Template.blobImage.rendered = function() {
Deps.autorun(function(c) {
Meteor.call('base64image', "1", function(err, imageArray) {
if (err) {
console.log(err)
return;
}
else {
console.log(imageArray);
console.log(typeof(imageArray));
if (typeof(imageArray) != 'undefined') {
console.log(imageArray);
console.log(typeof(imageArray));
for (var x in imageArray) {
$("#fileList").append('<img height="200" src="' + imageArray[x] + '" alt="' + x + '" />')
}
console.log("should have appended everything.");
c.stop();
}
}
});
})
}
// Template.blobImage.created = function() {
// var imageId = this.data;
// Meteor.call('base64image',imageId, function(err,imageString) {
// if (err) throw new err;
// if (!err && imageString)
// Session.set("img_" + imageId, imageString);
// });
// }
// Template.hello.greeting = function () {
// return "Welcome to testProd.";
// };
// Template.hello.events({
// 'click input': function () {
// // template data, if any, is available in 'this'
// if (typeof console !== 'undefined')
// console.log("You pressed the button");
// }
// });
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
ImagesFS.fileHandlers({
default1: function(options) {
// console.trace();
// console.log('I am handling default1: ' + options.fileRecord.filename);
return { blob: options.blob, fileRecord: options.fileRecord };
}
});
// server
Meteor.methods({
'base64image' : function(hmm) {
var info = ImagesFS.find({}, { sort: { uploadDate:-1 } });
if (!info)
return '';
var arrayImages = {};
info.forEach(function(image) {
var blob = ImagesFS.retrieveBuffer(image._id);
if (blob != undefined) {
var str = 'data:' + image.contentType + ';base64,' + blob.toString('base64');
arrayImages[image._id] = str;
}
});
// console.log(arrayImages);
return arrayImages;
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment