spring-boot - 相对于图像的访问。Jhipter 弹簧靴
问题描述
我有一个 Jhipster ( Spring Boot ) 项目,我需要将其作为附件添加到生成图像的电子邮件中。
问题是我不知道应该在后端文件夹中的哪个位置找到图像,或者如何从 Java 中进行相对引用,以便它在开发和生产中都可以使用
HttpResponse<String> response =
Unirest.post("https://api.infobip.com/email/1/send")
.header("Authorization", "Basic xxxx=")
.header("Accept", "application/json")
.field("from", "xxx Notifications <notifications-noreply@xxxx.com>", "text/plain")
.field("to", "joseluis.xxx@xxx.com", "text/plain")
.field("replyTo", "xxx@xxx.com", "text/plain")
.field("subject", "Prueba Full", "text/plain")
.field("text", "text prueba full", "text/plain")
.field("html", s, "text/plain")
.field("attachment", new File("/MI_IMAGEN.JPG"))
.field("bulkId", "cusotmBulkId", "text/plain")
.field("intermediateReport", "true", "text/plain")
.field("notifyUrl", "https://www.example.com/email/advanced", "text/plain")
.field("notifyContentType", "application/json", "text/plain")
.field("callbackData", "DLR callback data", "text/plain").asString();
就是这一行:
field("attachment", new File("/MI_IMAGEN.JPG"))
我需要将我的图像放置在我可以在开发和生产中以相对方式访问的路线中。
解决方案
不要在 build/ 文件夹中创建任何内容,因为构建工具(gradle 或 maven)使用它来编译和打包您的项目。它类似于 maven 的 target/ 文件夹。
将与邮件相关的图像和 html 模板放在 src/main/resources/mails/ 文件夹中。
推荐阅读
- php - 一个事务ID在数据库中多次插入
- php - MYSQL:SQLSTATE [22007]:日期时间格式无效
- ios - 为什么我的空 iOS 单视图应用程序项目会崩溃?
- c++ - C++ 中的多态性在幕后发生了什么?
- php - 使用 PHP,我如何能够在我的内容模板中加载锚定部分,从文件名中读取基于 id 的内容?
- python - Pandas:多索引数据帧索引 - 将值设置为数据帧子集
- android - 如何使用 PagerAdapter 在 ViewPager 中调用 destroyItem()
- java - 为什么我的数据库中的所有数据都没有显示到我的 JTextfield 上
- python - 在 Python 中从列表创建元组
- javascript - 展平路线树