Существует ли универсальный тип MIME для всех файлов изображений?

31168
cipricus

Я знаю, что могу использовать определенные типы MIME, перечисленные, например, здесь, или универсальный MIME-тип для любого файла, например application/octet-stream, но существует ли универсальный MIME-тип для всех файлов изображений?

(Я хочу отредактировать .desktopфайл в Linux Mint KDE, чтобы создать запись контекстного меню «Действие» в Dolphin File Manager, которая будет отображаться только для файлов изображений.)

23
Будет ли `image / *` работать (как браузеры)? Boldewyn 8 лет назад 1
@Boldewyn - `image / *` работает для цели, указанной в моем вопросе, даже для файлов `svg` - то есть как запись рабочего стола, такая как` MimeType = image / * `. Пожалуйста, ответьте [на этот более конкретный вопрос] (http://unix.stackexchange.com/q/232525/32012), ответ на который вы комментируете. cipricus 8 лет назад 0

2 ответа на вопрос

24
DavidPostill

Is there a generic mime-type for all image files?

Normally there isn't, but there are a couple of exceptions documented later in this answer.

You need a Mime Type in order to know how to process a file (without having to read the file header).

Notes:

  • Not all image files have a header that identifies their type.

  • SVG files, for example, are just XML files. So without the correct mimetype or extension there would be no way to correctly identify the type of the file.

  • Mime Types are specified as Content-Type/subtype

  • There isn't a Mime Type image/generic (See "Further reading" below for the full list of IANA registered image subtypes).


Does it mean that there is a mime-type for multiple image files?

There is no single Content-Type/subtype that covers multiple image formats.

In theory you could use an unknown Subtype such as image/xyz but W3C says explicitely:

"a Content-Type of image/xyz is enough to tell a user agent that the data is an image, even if the user agent has no knowledge of the specific image format xyz ... "such an action might be reasonable for unrecognized subtypes of text, but not for unrecognized subtypes of image or audio"

In general, the top-level Content-Type is used to declare the general type of data, while the subtype specifies a specific format for that type of data.

Thus, a Content-Type of "image/xyz" is enough to tell a user agent that the data is an image, even if the user agent has no knowledge of the specific image format "xyz".

Such information can be used, for example, to decide whether or not to show a user the raw data from an unrecognized subtype -- such an action might be reasonable for unrecognized subtypes of text, but not for unrecognized subtypes of image or audio.

For this reason, registered subtypes of audio, image, text, and video, should not contain embedded information that is really of a different type. Such compound types should be represented using the "multipart" or "application" types.

Source W3C - The Content-Type Header Field


Can I use a wildcard like image/* for my special case?

so that it can be used for my purpose without the need of specifying the singular file extensions/mimes?

Yes. As you have pointed out a wildcard can be used when specifying the "Desktop Entry" for the the KDE and GNOME desktop environments.

However, please note that Key=MimeType is deprecated as there is a new standard for this.

Type=MimeType is deprecated as there is a new standard for this now, see the Shared MIME-info Database specification for more information. In consequence the Keys Patterns (various file name extensions associated with the MIME type) and DefaultApp (the default application associated with this MIME type) are also deprecated.

Source Desktop Entry Specification

You can also use wildcards for mime types in IIS, but is advised to not do this:

You can also configure IIS to serve undefined file types by adding a wildcard character (*) MIME type.

Do not use wildcard MIME-types on production servers. Doing so can result in IIS serving unrecognized files and displaying sensitive information to users.

Wildcard MIME-types are intended for testing purposes or in scenarios where Internet Server API (ISAPI) filters have been developed specifically to handle these wildcard scenarios, for example, a custom authentication ISAPI.

Source Creating Global MIME Types


Further reading

Означает ли это, что существует ** MIME-тип для ** множественных ** файлов изображений - не для всех, а для многих, чтобы его можно было использовать для моих целей без необходимости указывать единственные расширения / mimes для файлов? cipricus 8 лет назад 0
@cipricus Не существует ** одного ** `content-type / subtype`, который охватывает несколько форматов изображений. DavidPostill 8 лет назад 2
@cipricus Ответ обновлен с учетом вашего комментария. DavidPostill 8 лет назад 0
как указано в комментарии под моим вопросом, `image / *` работает для цели, указанной в моем вопросе, даже для файлов `svg` - то есть как запись рабочего стола, такая как` MimeType = image / * `. cipricus 8 лет назад 0
Это может хорошо работать, но в соответствии с [Desktop Entry Specification] (http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html) - "` Type = MimeType` устарела как теперь для этого существует новый стандарт, см. спецификацию базы данных Shared MIME-info для получения дополнительной информации. В результате шаблоны ключей (различные расширения имени файла, связанные с типом MIME) и DefaultApp (приложение по умолчанию, связанное с этим типом MIME) также не рекомендуется ". DavidPostill 8 лет назад 0
Спасибо за хорошо документированный ответ. В качестве практического решения для моей ограниченной цели (создайте пункт контекстного меню «Действие» в Dolphin File Manager, который будет отображаться только для файлов изображений), работает `image / *`. В своем нынешнем виде ваш ответ является наиболее адекватным, но я не получаю положительного решения. Я задал [здесь] (http://unix.stackexchange.com/q/232525/32012) более конкретный вопрос. cipricus 8 лет назад 0
Я обновлю ответ, чтобы включить ваше решение для ограниченного случая. DavidPostill 8 лет назад 0
2
jrast

According to this SO-Answer there is no generic MIME-Type. The problem is that the MIME-Type is allways composed of a Type, a Subtype and a optional Parameter: Type/Subtype; Parameter (see here). You only want to use the type, but by definition a subtype is required and there is no generic subtype. A list of all image types can be found here.

Как ни странно, этот список «всех» типов изображений содержит пробелы для `gif` и` jpeg`, тогда как этот список https://www.sitepoint.com/web-foundations/mime-types-complete-list/ показывает, что они `image / gif` и` image / jpeg` соответственно. user664833 7 лет назад 0