Java Webapp-存储图像的位置 [英] Java Webapp - Where to store Images

查看:53
本文介绍了Java Webapp-存储图像的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Java Spring,Hibernate和JSP创建了一个Web应用程序.基本上,这是我从头开始制作的博客,因此有一个界面,我可以在其中添加带有图片的新博客文章.

I created a web application using Java Spring, Hibernate, with JSP's. It's basically a blog I made from scratch, so there's an interface where I can add a new blog post with pictures.

我使用Heroku托管和部署该应用程序.

I use Heroku to host and deploy the app.

当我想在博客文章中发布图像时,我会执行以下操作:

When I want to post images in a blog post, I do:

该图像当前存储在"WEB-INF"外部的资源文件夹中.除此以外,随着我​​添加更多博客文章,我将获得很多大型图片.我不知道应该将这些图像存储在何处以及如何访问它们.我本来打算将其存储在文件系统中,但是每次添加更多图像时,我都不必在heroku上重新部署该应用程序吗?另一个选择是拥有一个公共的保管箱文件夹,然后将图像链接在那里,但这将使我的整个保管箱目录向公众开放.有没有更好的方法来完成所有这些工作,尤其是管理这么多大图片?

And that image is currently stored in a resource folder right outside of 'WEB-INF'. Except, as I add more blog posts, I will have a lot of large sized pictures. I don't know where I should store these images and how I should access it. I thought of storing it in the file system, but wouldn't I have to re-deploy the app on heroku each time I add more images? Another option was having a public dropbox folder and linking the images there, but that would open up my entire dropbox directory to the public. Is there a better way to do all of this, especially managing so many large pictures?

推荐答案

在文件系统中保存文件不是可伸缩的解决方案.如果您为网络应用添加新服务器,则对于任何请求,图片均无法正确显示.

Saving files in file system is not a scalable solution. If you add new servers for your web app the images won't be displayed correctly for any request.

您必须将图像保存在分布式环境中.它可以是数据库(例如Postgres)或Amazon S3存储系统上的LOB列.

You have to save your images in a distributed environment. It can be a LOB column on the database (Postgres for example) or an Amazon S3 storage system.

访问类型非常不同,但是对于您的图像而言,两个系统都是不错的选择.如果它们很大,则S3是最佳选择.

The access type is very different but both systems are a good option for your images. If they are big in size, S3 is the best option.

这篇关于Java Webapp-存储图像的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆