相对于图像的访问。 Jhipter春季靴子

时间:2018-11-15 08:31:30

标签: spring-boot jhipster

我有一个使用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"))

我需要将自己的图像放置在可以在开发和生产中以相对方式访问的路径中。

1 个答案:

答案 0 :(得分:0)

不要在build /文件夹中创建任何东西,因为构建工具(gradle或maven)使用它来编译和打包项目。它类似于Maven的target /文件夹。

将与邮件相关的图像和html模板放入src / main / resources / mails /文件夹中。