将文件系统上的文件夹映射到 Tomcat 中的 url 最简单的方法是什么?
这是我的问题...我有一个小型原型应用程序(恰好位于 AWS 上托管的 Grails 中),我想添加用户上传一些(最多 10 张)图像的功能。我想将这些图像保留在服务器计算机的磁盘上,位于我的 WAR 之外的文件夹位置。
我意识到可能有一个超级可扩展的解决方案,涉及更多的 Web 服务器和优化的静态资产服务,但对于我可能获得的大约 100 个用户来说,这确实不值得付出努力和成本。
那么,将虚拟文件夹从我的 url 映射转移到磁盘上的物理文件夹的最简单方法是什么?我有点想...
http://myapp.com/static
映射到一个我可以配置的文件夹,例如
/var/www/static
这样我就可以在我的代码中...
<img src="/static/user1/picture.jpg"/>
我并不特别介意生成的物理文件夹是否可以直接浏览。安全最终会成为一个问题,但一开始并不是这样。
那么,我有什么选择呢?我查看了apache网站上的虚拟主机,但感觉比我需要的更复杂。
我不想使用 Grails 静态渲染插件。
Here's my problem... I have a small prototype app (happens to be in Grails hosted on AWS) and I want to add the ability of the user to upload a few (max 10) images. I want to persist these images on disk on the server machine, in a folder location which is outside my WAR.
I realise that there is probably a super-scalable solution involving more web servers and optimised static asset serving, but for the approximately 100 users I am likely to get, it's really not worth the effort and cost.
So, what is the simplest way I can have a virtual folder from my url map to a physical folder on disk? I sort of want...
http://myapp.com/static
to map to a folder which I can configure e.g.
/var/www/static
so I can then have in my code...
<img src="/static/user1/picture.jpg"/>
I don't particularly mind whether the resulting physical folders are directly browsable. Security will eventually be an issue, but it isn't at the start.
So, what are my options? I have looked at virtual hosts on the apache site, but it feels more complicated than I need.
I don't want to use the Grails static rendering plugins.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了类似的问题,最终构建了自己的 servlet 来读取文件并将其流式传输到输出。问题是,如果您不支持 mime 类型、gzip、etag 和缓存标头(例如 Last-Modified),这可能会非常低效。我最终对所有这些进行了编码(并使用 ehcache 进行服务器端缓存),但这并不简单。
然而,这个 StackOverflow 问题有许多有用的答案。
将文件系统上的文件夹映射到 Tomcat 中的 URL 的最简单方法是什么?
更具吸引力的选项之一似乎是 FileServlet。
http://balusc.blogspot.com/2009/02/ fileservlet-supporting-resume-and.html
I had a similar problem and ended up building my own servlet to read in a file and stream it to the output. The catch is that if you don't support mime types, gzip, etags, and cache-headers (such as Last-Modified) this can be very inefficient. I ended up coding all of these (and using ehcache for server side caching), but it's not simple.
However, this StackOverflow question has a number of useful responses.
What is the simplest way to map a folder on the file system to a url in Tomcat?
One of the more appealing options seems to be FileServlet.
http://balusc.blogspot.com/2009/02/fileservlet-supporting-resume-and.html