Dealing with mass images, some small - some large, in spring/java application using mysql
I was wondering what the best pattern was to handle the management of images these days when using spring/java and mysql.
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?
For the larger images, is file system pretty much the only option, and then use mysql to store the location on the file system?
Where is a good spot to put them on a linux server? /var/files/images?
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?
Also, do I have to develop all of the file management stuff myself, like cleaning up 开发者_如何学Gounused files and the like?
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 :)
精彩评论