Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (Meteor.isClient) {
- Template.myForm.events({
- 'change .myFileInput': function(event, template) {
- FS.Utility.eachFile(event, function(file) {
- var fsFile = new FS.File(event.target.files[0]);
- fsFile.owner = Meteor.userId();
- Images.insert(file, function (err, fileObj) {
- //If !err, we have inserted new doc with ID fileObj._id, and
- //kicked off the data upload using HTTP
- });
- });
- }
- });
- Template.imageView.helpers({
- images: function () {
- return Images.find(); // Where Images is an FS.Collection instance
- }
- });
- Meteor.subscribe('images');
- }
- if (Meteor.isServer) {
- Meteor.startup(function () {
- // code to run on server at startup
- });
- Meteor.publish('images', function(){
- return Images.find();
- });
- }
- Images = new FS.Collection("images", {
- stores: [new FS.Store.FileSystem("images", {path: "~/uploaded"})],
- });
- Images.allow({
- insert: function(userId, doc){
- return !!userId;
- },
- update: function(userId, doc){
- return !!userId;
- },
- remove: function(userId, doc){
- return false;
- }
- });
- <head>
- <title>uploader</title>
- </head>
- <body>
- {{> loginButtons}}
- {{> imageView}}
- {{>myForm}}
- </body>
- <template name="imageView">
- <div class="imageView">
- {{#each images}}
- <div>
- <a href="{{this.url}}" target="_blank"><img src="{{this.url}}" alt="" class="thumbnail" />{{this.url}}</a><br/>
- <strong>{{this.name}}</strong> <a href="{{this.url download=true}}" class="btn btn-primary">Download</a>
- </div>
- {{/each}}
- </div>
- </template>
- <template name="myForm">
- <p>
- Please specify a file, or a set of files:<br>
- <input type="file" name="datafile" class="myFileInput">
- </p>
- </template>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement