Advertisement
Guest User

Untitled

a guest
Oct 1st, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. if (Meteor.isClient) {
  2. Template.myForm.events({
  3. 'change .myFileInput': function(event, template) {
  4. FS.Utility.eachFile(event, function(file) {
  5. var fsFile = new FS.File(event.target.files[0]);
  6. fsFile.owner = Meteor.userId();
  7. Images.insert(file, function (err, fileObj) {
  8. //If !err, we have inserted new doc with ID fileObj._id, and
  9. //kicked off the data upload using HTTP
  10. });
  11. });
  12. }
  13. });
  14.  
  15.  
  16. Template.imageView.helpers({
  17. images: function () {
  18. return Images.find(); // Where Images is an FS.Collection instance
  19. }
  20. });
  21. Meteor.subscribe('images');
  22. }
  23.  
  24.  
  25.  
  26.  
  27.  
  28. if (Meteor.isServer) {
  29. Meteor.startup(function () {
  30. // code to run on server at startup
  31. });
  32. Meteor.publish('images', function(){
  33. return Images.find();
  34. });
  35. }
  36.  
  37.  
  38. Images = new FS.Collection("images", {
  39. stores: [new FS.Store.FileSystem("images", {path: "~/uploaded"})],
  40. });
  41.  
  42. Images.allow({
  43. insert: function(userId, doc){
  44. return !!userId;
  45. },
  46. update: function(userId, doc){
  47. return !!userId;
  48. },
  49. remove: function(userId, doc){
  50. return false;
  51. }
  52. });
  53.  
  54. <head>
  55. <title>uploader</title>
  56. </head>
  57.  
  58. <body>
  59. {{> loginButtons}}
  60. {{> imageView}}
  61. {{>myForm}}
  62. </body>
  63.  
  64. <template name="imageView">
  65. <div class="imageView">
  66. {{#each images}}
  67. <div>
  68. <a href="{{this.url}}" target="_blank"><img src="{{this.url}}" alt="" class="thumbnail" />{{this.url}}</a><br/>
  69. <strong>{{this.name}}</strong> <a href="{{this.url download=true}}" class="btn btn-primary">Download</a>
  70. </div>
  71. {{/each}}
  72. </div>
  73. </template>
  74.  
  75. <template name="myForm">
  76. <p>
  77. Please specify a file, or a set of files:<br>
  78. <input type="file" name="datafile" class="myFileInput">
  79. </p>
  80. </template>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement