0

I am writing a Spring Rest service which will have to return a file with extension .oft (ex Like Sample.oft)

This oft file will be opened in Microsoft outlook application. But I don't find any specific MimeType to set in ResponseEntity object.

If I need create custom mime type, how do I implement it?

Else is there any other file extension I can use? (.eml extension does not work either)

Renga
  • 3
  • 2

1 Answers1

0

Mime-Type for OFT

Microsoft Outlook Email Template (.oft) has basically the same format as .msg. It's proven that Outlook Emails (.msg) are associated properly by following Mime-Type:

application/vnd.ms-outlook

So I would suggest to use this Mime-Type, because will ensure:

  • file is application specific
  • file should be handled by vendor or application (vnd) MS Outlook

File Response using Spring

See Baeldung's tutorial 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);
}

Note: Above implementation uses Apache's IOUtils.

See also: Downloading a file from spring controllers

hc_dev
  • 8,389
  • 1
  • 26
  • 38
  • I am able to download it. But when I try to open it, it says that "the file is already opened or you don't have permission". But the file is not opened and I have permission too. – Renga Apr 16 '20 at 21:32
  • @Renga Glad **my answer solved your question** for _mime-type_ and _spring-implememtation_ and **you can download** For the next _opening-fails_ issue **please post a separate question!** Or research: https://kc.mcafee.com/corporate/index?page=content&id=KB86515 – hc_dev Apr 16 '20 at 22:16