java webapp上传图片访问URL

发布于 2024-12-23 12:03:36 字数 717 浏览 4 评论 0原文

我的网络应用程序允许最终用户上传图像。将图像保存到服务器后,即可在我的网站上查看该图像。为了使网络应用程序更容易扩展,我决定根据当前时间将上传的图像存储到不同的文件夹中,例如:

/images/upload/2011/11/30/image1.jpg 
/images/upload/2011/11/30/image2.jpg 
/images/upload/2011/12/29/image1.jpg
/images/upload/2011/12/29/image2.jpg

这样就可以了。然而,最终用户的图像 URL 还将包含以下信息:

http://www.mywebapp.com/images/upload/2011/11/30/image1.jpg

这是不可取的。我想知道是否可以生成“2011/11/30/image1.jpg”的摘要,如“8faa6933ac54cd2ae5eb575d2d966a42.jpg”,将映射保存在某处,然后为最终用户提供

http://www.mywebapp.com/images/8faa6933ac54cd2ae5eb575d2d966a42.jpg

:进来后,我们从之前保存的映射中查找真实图像,并为真实图像提供服务。

是否可以达到上述目的?或者根本不相关。我在我的应用程序中使用 spring mvc。

谢谢您的宝贵时间, 乔治

My web application allows end users to upload image. After the image is saved to server, the image will then be viewable at my web site. To make the webapp easier to scale, I decide to store the uploaded image into different folder based on current time, like:

/images/upload/2011/11/30/image1.jpg 
/images/upload/2011/11/30/image2.jpg 
/images/upload/2011/12/29/image1.jpg
/images/upload/2011/12/29/image2.jpg

This is ok. However the image URL for end user will also include information like:

http://www.mywebapp.com/images/upload/2011/11/30/image1.jpg

which is not desireable. I am wondering whether it is possible to produce the digest for "2011/11/30/image1.jpg" as something like "8faa6933ac54cd2ae5eb575d2d966a42.jpg", save the mapping somewhere, and then serve end user with:

http://www.mywebapp.com/images/8faa6933ac54cd2ae5eb575d2d966a42.jpg

When the request for the image comes in, we look up the real image from the previously saved mapping, and serve the real image.

Is it possible to achieve the above? Or it is not relevant at all. I am using spring mvc for my application.

Thank you for your time,
George

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷路的信 2024-12-30 12:03:36

您可以编写一个 servlet 来捕获这些 url 并将图像作为字节流传递给用户。

You could write a servlet that catches those urls and pass the image to the user as a byte-stream.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文