Dropwizard服务外部图像目录 [英] Dropwizard serve external images directory

查看:73
本文介绍了Dropwizard服务外部图像目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个dropwizard API应用程序,我想要一个端点,我可以在该端点上运行调用并上传图像,这些图像必须保存在目录中,然后通过同一应用程序上下文提供服务.

dropwizard可能吗?我只能找到静态资产包.

解决方案

已经存在类似的问题:第三方模块列表中提到了上述模块.还有官方模块列表.很难找到这两个列表,可能是因为主要文档没有引用它们.

还有 dropwizard-file-assets ,它似乎很新.我不知道哪个模块最适合您的情况.两者均基于dropwizard简单项目使用 dropwizard-configurable-assets-bundle 制作.请按照README.md中的说明进行操作.我认为它确实可以满足您的要求:将一些文件放在文件系统上某个目录的某个目录中(项目源代码之外),然后将它们提供(如果存在).

I have a dropwizard API app and I want one endpoint where I can run the call and also upload and image, these images have to be saved in a directory and then served through the same application context.

Is it possible with dropwizard? I can only find static assets bundles.

解决方案

There is similar question already: Can DropWizard serve assets from outside the jar file?

The above module is mentioned in the third party modules list of dropwizard. There is also official modules list. These two lists are hard to find maybe because the main documentation doesn't reference them.

There is also dropwizard-file-assets which seems new. I don't know which module will work best for your case. Both are based on dropwizard's AssetServlet

If you don't like them you could use it as example how to implement your own. I suspect that the resource caching part may not be appropriate for your use case if someone replace the same resource name with new content: https://github.com/dirkraft/dropwizard-file-assets/blob/master/src/main/java/com/github/dirkraft/dropwizard/fileassets/FileAssetServlet.java#L129-L141

Edit: This is simple project that I've made using dropwizard-configurable-assets-bundle. Follow the instructions in the README.md. I think it is doing exactly what you want: put some files in a directory somewhere on the file system (outside the project source code) and serve them if they exist.

这篇关于Dropwizard服务外部图像目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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