Dropwizard 提供外部图像目录

Dropwizard serve external images directory

我有一个 dropwizard API 应用程序,我想要一个端点,我可以在其中 运行 调用并上传和图像,这些图像必须保存在一个目录中,然后通过相同的应用程序上下文。

dropwizard 可以吗?我只能找到静态资源包。

已有类似问题:Can DropWizard serve assets from outside the jar file?

third party modules list of dropwizard. There is also official modules 列表中提到了上述模块。这两个列表很难找到,可能是因为主要文档没有引用它们。

还有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

如果您不喜欢它们,您可以使用它作为示例如何实现您自己的。我怀疑如果有人用新内容替换相同的资源名称,resource caching 部分可能不适合您的用例:https://github.com/dirkraft/dropwizard-file-assets/blob/master/src/main/java/com/github/dirkraft/dropwizard/fileassets/FileAssetServlet.java#L129-L141

编辑: 这是 simple project that I've made using dropwizard-configurable-assets-bundle。按照 README.md 中的说明进行操作。我认为它正在做你想要的事情:将一些文件放在文件系统某处的目录中(在项目源代码之外)并在它们存在时提供它们。