【问题标题】:Access relative to image. Jhipter Spring Boot相对于图像的访问。 Jhipster 弹簧靴
【发布时间】:2019-04-18 07:19:59
【问题描述】:

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

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

【问题讨论】:

    标签: spring-boot jhipster infobip infobip-api


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-07-15
      • 1970-01-01
      • 1970-01-01
      • 2017-12-22
      • 2018-02-14
      • 2019-05-03
      • 2021-04-20
      • 1970-01-01
      • 2023-01-07
      相关资源
      最近更新 更多