Reputation: 5254
/lib/collections/images.js
var imageStore = new FS.Store.FileSystem("images", {
// what should the path be if I want to save to /public/assets?
// this does not work
path: "/assets/images/",
maxTries: 1
});
Images = new FS.Collection("images", {
stores: [imageStore]
});
Images.deny({
insert: function() {
return false;
},
update: function() {
return false;
},
remove: function() {
return false;
},
download: function() {
return false;
}
});
Images.allow({
insert: function() {
return true;
},
update: function() {
return true;
},
remove: function() {
return true;
},
download: function() {
return true;
}
});
/client/test.html
<template name="test">
<input type="file" name="myFileInput" class="myFileInput">
</template>
/client/test.js
Template.test.events({
'change .myFileInput': function(event, template) {
FS.Utility.eachFile(event, function(file) {
Images.insert(file, function (err, fileObj) {
if (err){
// handle error
} else {
// handle success
}
});
});
},
});
For the path, if I use:
path: "/public/assets/images",
Error: EACCES, permission denied '/public'
path: "/assets/images",
Error: EACCES, permission denied '/assets'
path: "~/assets/images",
This works, but it saves the image to /home/assets/images
on my Linux machine. The path isn't relative to the Meteor project at all.
Upvotes: 2
Views: 2194
Reputation: 71
I have resolved this issue using meteor-root package: https://atmospherejs.com/ostrio/meteor-root
Files = new FS.Collection("files", {
stores: [new FS.Store.FileSystem("images", {path: Meteor.absolutePath + '/public/uploads'})]
});
So now it stores files in app/public/uploads/
Hope this helps!
Upvotes: 7
Reputation: 25
You can use
var homeDir = process.env.HOMEPATH;
tmpDir: homeDir + '/uploads/tmp'
Upvotes: 0
Reputation: 2386
/
doesn't stand for root of your site. /
stands for root of your system. The meteor app runs as your user.
What you'll want do, is use a relative path. It's possible that the collectionFS fs.write
operation isn't done from the apps root. So alternatively you could use path: process.env.PWD + '/public/assets/images'
Upvotes: 5