veliovgroup / Meteor-Files

🚀 Upload files via DDP or HTTP to ☄️ Meteor server FS, AWS, GridFS, DropBox or Google Drive. Fast, secure and robust.
https://packosphere.com/ostrio/files
BSD 3-Clause "New" or "Revised" License
1.11k stars 166 forks source link

Question: Save link in database? #873

Open aertms opened 1 year ago

aertms commented 1 year ago

I have a question about this package and what would be the best way to use it in our case. We use it to upload files to S3. This question is specifically about users' profile pictures. I looked through the documentation but didn't find anything specific about this question, sorry if I missed something.

What we've been doing so far: When the users change their profile pictures the new picture is uploaded and the filename is set to <userId>.jpg. The old profile picture is deleted. When I need to show the profile picture I have a component that includes a subscription to that file object with the filename as parameter, which I get from the user id. And then I set the image tag with <img src={file.link()} />.

When the profile pictures are shown in a lot of different places it creates a lot of subscriptions and I'm wondering if that's the best way to do it or if there is a better way.

An alternative I thought of is this: When uploading the profile picture I immediately get the link() of the file and save that in the user object. So in other places in the app where I currently save the userId and the userName I could also save the userPictureUrl. That way I have access to the url directly and don't need to subscribe to the file object.

Would that be better than subscribing to all the files individually, also from a performance point of view? Or are there other best practices for a use case like this?