-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Support additional mime types in MediaType class [SPR-13873] #18446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Rossen Stoyanchev commented Not acceptable just means there is no |
Sachin Walia commented I guess, not acceptable is a little strong word. The point I was making is that both these mime types are supported by browsers (webp by chrome only) and SVG by all modern browsers so natively supporting these two mime types is helpful. Otherwise we have to make use of http headers to set the content type which works but not the most preferred way. application/octet-stream is typically used in file download scenario where browser cannot render the file and you want to use native application to handle viewing that file. |
Rossen Stoyanchev commented I meant "not acceptable" as in HTTP status code 406. Can you provide an example of what you're trying to do? Not a full-blown example, just snippet of controller code. |
Rossen Stoyanchev commented Sachin Walia, your comments please? Also what are you using to support conversion to this image type? |
Sachin Walia commented Hi, sorry for the late reply. Here is the workflow:
InputStreamResource inputStreamResource = //Get some inputstream resource;
long contentLength = //get file length
String mediaType = "image/webp" //different depending upon file type
if(inputStreamResource != null){
return ResponseEntity.ok().contentLength(contentLength).header("Content-type",mediaType).body(inputStreamResource );
} else {
response.messageCode = "SOME_ERROR_CODE";
response.message = applicationContext.getMessage(response.messageCode, null, null);
return ResponseEntity.ok(response);
} Because MediaType class doesn't support mime "image/webp" so I have to use HttpHeader to set this content type else ResponseEntity will be returned as: return ResponseEntity.ok().contentLength(contentLength).contentType(MediaType.parseMediaType(mediaType)).body(inputStreamResource );
|
Rossen Stoyanchev commented Okay I see now I was thrown off originally by the word support. I guess you just mean adding more constants to MediaType? There are literally thousands of these. Currently the cutoff is roughly at the ones we support serialization for (JSON, XML, etc.) Why not create some constants of your own? |
Sébastien Deleuze commented Resolving as incomplete given the lack of feedback. |
Sachin Walia opened SPR-13873 and commented
Following mime types are common place in web environment. However Spring MVC MediaType class just throws exception if we try to use their correct mime type. Moreover using application/octet-stream is also not an acceptable solution
Moreover there should be some way to define custom media type for any additional mime types.
No further details from SPR-13873
The text was updated successfully, but these errors were encountered: