Access to the FS collection denied 403 error #Meteor JS

I use collectionFS to upload files, my code is below. The recorded user can insert the image into the image collection, also I see that the file is uploaded to the server. Links to the image and the download button are displayed before removing an unsafe package that can see images and download. After removing an unsafe package from the project. Images are not displayed, and the download does not work (it can get the name and URL of the image), error 403 is denied when gaining access. I really wanted the signed-in user to be able to upload files to the server and everyone can see the images, as well as upload files . I wrote the rules, and publish and subscribe. What is the problem?
js file

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; } }); 

html file

  <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> 
+7
javascript mongodb meteor
source share
1 answer

If you have insecurity and auto-publishing is turned off and you access your files through a subscription, I believe that you just need to load var into your allowed hash.

 Uploads.allow({ insert:function(userId,project){ return true; }, update:function(userId,project,fields,modifier){ return true; }, remove:function(userId,project){ return true; }, download:function(){ return true; } }); 
+18
source share

All Articles