Toby
Toby

Reputation: 8792

FS.Collection throwing 403 Forbidden Errors

Up until recently this code was working as expected, media files could be uploaded, saved into Mongo and then retrieved using their stores.

During a routine test of the system I noted that this has stopped working and we are getting Access denied [403] errors anytime we try and upload media both locally and in production.

All my research suggests that setting insert/update/download to be true would work. To debug in the code below everything is set to true and I am still getting this 403

Any guidance would be hugely appreciated.

Collection Information

Media = new FS.Collection("media", {
  stores: [
    mediaStoreGrid,
    mediaStoreGridThumbnail,
    mediaStoreGridOptions,
    mediaStoreGridLightbox,
    mediaStoreGridLogo
  ]
});

Media.allow({
  insert: function(userId, project) {
    return true;
  },
  update: function(userId,project,fields,modifier) {
    return false;
  },
  remove: function(userId,project) {
    return true;
  },
  download: function() {
    return true;
  }
});

Call to save Media

// We just care about the first file
var files = $('.descriptive-image').get(0).files;
if (files.length > 0) {
  var media = Media.insert(files[0]);
  Meteor.subscribe('mediaItem', media._id);
  return [media._id];
} else {
  return [];
}

Upvotes: 0

Views: 135

Answers (1)

Brian Shamblen
Brian Shamblen

Reputation: 4703

FS.Collection insert takes an FS.File as the argument, not the raw file input object. Try this:

var mediaFile = new FS.File(files[0]);
var media = Media.insert(mediaFile);

Upvotes: 1

Related Questions