Support for MIME types - Core issue

Hey, I am currently working on RESTWS-641 issue, which is about supporting MIME types when posting complex obs. I faced problem where ContentType of my response was always "application/octet-stream". After investigating code I’ve realized that it is caused by BinaryDataHandler, which always sets ComplexData's mimeType to "application/octet-stream" value. Check out code below:

As a solution I would just pass file.getContentType() as setMimeType() argument instead of fixed String value. What do You think? :slight_smile: Tomek

Your proposal makes a lot of sense to me. :smile:

1 Like

That seems to make sense, but I’d imagine that fixing it in core can be done in a separate ticket, my question is can’t we get the rest module working with mime types regardless of what you get back, with this ticket what we want is for one to be able to get back the complex data via rest

I assume you mean file.toURI().toURL().openConnection().getContentType(). This can return null, so you’d still need to have a default value if it’s null. Also, worth consideration:

1Get the Mime Type from a File

Thats the way I did it: mimeType = Files.probeContentType(file.toPath()); and then, to ensure there is default value when something goes wrong: mimeType = mimeType != null ? mimeType : "application/octet-stream";

PS. Here is PR with changes: https://github.com/openmrs/openmrs-core/pull/1982#partial-pull-merging

This might be a stupid question so please bear with me, but apart from being somehow cleaner to assign the correct MIME type, how does it affect the front-end?

I mean the browser seems to know how to display the picture I uploaded even with the current way of handling.

@flobue how about other clients which may not be as intelligent as the browser? :smile: