Spring 响应实体 mimetype 中的 OFT 文件

OFT file in Spring response entity mimetype

我正在编写一个 Spring 休息服务,它必须 return 一个扩展名为 .oft 的文件(例如 Sample.oft)

该文件将在 Microsoft Outlook 应用程序中打开。但是我没有在 ResponseEntity 对象中找到要设置的任何特定 MimeType。

如果我需要创建自定义 MIME 类型,我该如何实现?

还有我可以使用的其他文件扩展名吗? (.eml 扩展名也不起作用)

OFT 的 Mime 类型

Microsoft Outlook Email Template (.oft) has basically the same format as .msg. It's proven that 通过以下 Mime 类型正确关联:

application/vnd.ms-outlook

所以我建议使用这个 Mime-Type,因为可以确保:

  • 文件是应用程序特定的
  • 文件应由供应商或应用程序处理 (vnd) MS Outlook

文件响应使用 Spring

查看 Baeldung 的教程 Download an Image or a File with Spring MVC:

@GetMapping(
  value = "/download-oft",
  produces = "application/vnd.ms-outlook"
)
public @ResponseBody byte[] getFile() throws IOException {
    InputStream in = getClass()
      .getResourceAsStream("/path/to/your/email_template.oft");
    return IOUtils.toByteArray(in);
}

注意:以上实现使用了Apache的IOUtils.

另请参阅: Downloading a file from spring controllers