Dealing with mass images, some small - some large, in spring/java application using mysql

StackOverflow https://stackoverflow.com/questions/4414193

سؤال

I was wondering what the best pattern was to handle the management of images these days when using spring/java and mysql.

  1. I have several options. Some of the images are just small avatars for the users. Is it fine to put these directly into mysql? Or use the file system?

  2. For the larger images, is file system pretty much the only option, and then use mysql to store the location on the file system?

  3. Where is a good spot to put them on a linux server? /var/files/images?

  4. Since the files are hidden from the war deployment directory, what is the best way to stream them? Use some kind of a file output stream as the response body for an http request?

  5. Also, do I have to develop all of the file management stuff myself, like cleaning up unused files and the like?

  6. What about image security? Some images should not be accessed by everyone. I think I'd need to use a separate url with Spring security checking the current user for this.

I'd appreciate advice on all of these questions. Thanks.

هل كانت مفيدة؟

المحلول

You could use MySQL, and that would have the advantage of centralization and easy cleanup, but IMHO it's a waste of the database's resources if you plan to scale.

For data like images where everything is public, consider something like Amazon S3 which allows you to serve images directly from S3's web servers. If you plan to host everything yourself, just serve from a directory. Just remember to turn directory listings off :)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top