Meteor-CollectionFS icon indicating copy to clipboard operation
Meteor-CollectionFS copied to clipboard

Client refresh on file upload

Open mildful opened this issue 11 years ago • 4 comments

Hi,

I've a little issue with CollectionFS.

I'm using the FileSystem storage adaptator and it works well ! When I insert a file (client-side) it goes into my folder but after each insertion, the client is refreshed.

Here is some parts of my code if that can help :

//client-side
const field = document.getElementsByName('avatar')[0];

Avatars.insert(field.files[0], function (err, fileObj) {
    if (err) {
        //invalid file
        console.log(err);
    } else {
        console.log(fileObj);
    }
});

//server-side 
Avatars = new FS.Collection("avatars", {
    stores: [
        new FS.Store.FileSystem("original", { path: `${Meteor.settings.public.folder}/images/user/avatar/original` })
    ],
    filter: {
        maxSize: 1000000, 
        allow: { contentTypes: ['image/*'] }
    }
});

Maybe this is caused by a reactive data source ?

mildful avatar Nov 11 '15 14:11 mildful

It refreshes because you put it into the meteor app's folder. Any changes in the meteor app's folder trigger a refresh. You can use any folder on your system, just make sure the user executing the meteor app has the correct permissions for that folder.

nooitaf avatar Nov 11 '15 19:11 nooitaf

Okay, thanks.

Using Meteor, is it a better practice to save the files on a cloud like the S3 ? Saving uploaded files elsewhere than the app/public folder seems weird.

mildful avatar Nov 11 '15 23:11 mildful

You can think of the meteor app folder as everything your app needs to run. Uploaded content or any data that gets added later, be it files or database entries, should be seen as their own environments. As soon as you run in production you will for example need a mongodb server somewhere. Storing your files in S3 or directly in mongodb (GridFS) you are able to update your app without overwriting any data. You can even run multiple intances of your app at the same time without having to sync files around. As you already going to need a mongodb, GridFS is the quick and easy choice. And if you don't do file transforms you can even deploy on meteor.com and have your data persistent.

nooitaf avatar Nov 11 '15 23:11 nooitaf

Okay, now I get more the Meteor way of thinking. Thanks a lot for those clear answers. I have one last question :

  • Does storing files in MongoDB with GridFS does mean loosing some performance ? I'm relatively new to MongoDB but for example (maybe stupid ?) I'll never store an image into a SQL database or something like that. This is not really clean.
  • Will using a distant service like the S3 slow down image loading ? (Because the file aren't saved locally, so there is a retrieve time). Is it a good idea to use things like service workers to cache those files client-side and gain some performances ? (But I think that Meteor have this technology in its core to be able to render sites offline)

mildful avatar Nov 12 '15 13:11 mildful