Is there a standard 'null' mime-type

2020-04-07 17:49发布

问题:

I am using a single JSON response format to cover a number of possible responses.

The response contains a field that, optionally, contains a link to an external resource.

The response is valid, regardless of whether this field is populated.

I am using a separate mime-type field to dictate how the client should handle said field.

i.e.

mime-type : video/mp4

Client plays the video

mime-type : text/html

Client launches a browser with the given URL

What I would like to know, is if there is a "standard" mime-type to cover an empty resource.
I know I can use a vendor specific mime-type, and most likely will, but it made me question.

Thanks.

回答1:

I agree with DanielTate's comment on the original question: I don't think there is a "null media type" (media type a.k.a. MIME type). I haven't looked through the entire IANA registry, but I very much doubt there's anything there. The media type RFC doesn't appear to mention anything like this -- I haven't read the whole thing, but did scan the TOC and search around for "null" "empty" "invalid".

What's clear is: media type is supposed to be metadata about something. Given your question, I'm trying to guess why you might be thinking about a null media type (if you added some specific json examples in your question, it might be clearer), but, generally speaking, it just doesn't make much sense: in theory, you shouldn't need to describe nothing (i.e., a non-existing resource) with any kind of media type: there's already nothing there, so why describe it further as having a "null media type"?

If I understand your situation correctly, when there is no resource, I would just use an empty string. Maybe that's the null media type :) But, for some reason, you seem to really want to specify a media type in your response, even when there's no resource (or no link). Why is that?



回答2:

The IANA reserves "example" for, well, example purposes. But since "example" shall never be used as a real mime type, example/example could serve as an (internally used) compatible "null" MIME type.

https://www.iana.org/assignments/media-types/media-types.xhtml#examples

example

Note: The 'example' media type is used for examples. Any subtype following the media type syntax may be used in those examples. No subtype can be registered with IANA. For more information see[RFC4735].

Note: The occurrence of an 'example' media type as a media type outside of examples, e.g. in a Content-Type header, is an error and should be reported to the implementor.[RFC2045][RFC2046] specifies that Content Types, Content Subtypes, Character Sets, Access Types, and conversion values for MIME mail will be assigned and listed by the IANA.



回答3:

jus add a comma at the end

if( checkType( $_FILES["CV"]["type"], "application/pdf,image/jpeg,image/png,video/mp4,audio/mpeg,application/msword,application/excel,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.wordprocessingml.document," ) ) {