1

I am trying to save uploaded images into public/images folder of my meteor project, so I wrote this code.

Images = new FS.Collection("images", {
  stores: [new FS.Store.FileSystem("images", {path: "images"})]
});

But when I upload images, the files are saved into

.meteor/local/build/programs/server/images/

folder instead of public/images folder.

So how can I set path or what to save images to public/images folder instead of .meteor folder?

I will explain why I need it.

I have one other collection, buildings, which has this format.

Schemas.Buildings = new SimpleSchema({
  'name': {
    type: String,
    label: 'What is the name of the building?',
    max: 200,
    unique: true
  },
  'picture': {
    type: String,
    max: 200,
    optional: true,
    label: " ",
    autoform: {
      afFieldInput: {
        type: 'fileUpload',
        collection: 'Images',
        accept: 'image/*',
        label: 'Choose Aerial Image'
      }
    }
  }

And because I need to set sample buildings with pictures, so I need to put sample images to public/images/ folder and use them to set picture values of sample buildings in Meteor.startup bootstrap.

If I put that images to .meteor folder, it will be removed by meteor reset command, so I hope to persist the images to public folder.

Please teach me!

Samuel Jansson
  • 329
  • 1
  • 3
  • 13
  • Is it obligatory to store the files on the server or you just want to store the images (for example some free cloud service will be a better choice)? It is easy to configure and you have good control over the uploaded files. – StefanL19 Mar 12 '16 at 10:33
  • Let me edit my question for more detail. – Samuel Jansson Mar 12 '16 at 12:58

1 Answers1

1

If you want to save to the public folder you can use the path:

"../../../../../public/"

The reason why I didn't expect you would want to do that is that this refreshes your app each time something gets uploaded. When your path is set as:

"../web.browser/images/"

Your images can be accessed the same way as in the public folder, but as you stated before, this deletes them when the server restarts.

If you want your images to be accessible beyond a server restart/reset and want to prevent them from refreshing your application upon save, you should store them outside your project-folder. For instance you could create a map 'myImages' on the same level as your Meteor projects. The save location should then be:

"../../../../../../myImages/"

When you deploy your app a different folder structure applies, and when you add a similar image folder on the level of your Meteor project folders, the save location should be:

"../../../../myImages/"

In this case you probably also have to set some permissions, before this works, but that's probably too elaborate for this post.

Joos
  • 383
  • 1
  • 10
  • Thanks for your care, @Joos. I tried with your path, but it seems you misunderstood my requirements. I don't want pubic/images folder content to web.brower/images folder, but want the reverse case, namely, save images into public/images folder. – Samuel Jansson Mar 12 '16 at 12:54
  • Alright, I changed my answer to reflect a public save, or (as I expect) a more ideal solution, since saving directly to the public folder triggers your app to refresh – Joos Mar 12 '16 at 17:05