Project

General

Profile

Actions

Patch #32146

closed

Add more supported mimetypes

Added by Anonymous over 4 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Files
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

Description

The patch adds more mime-types which are supported by browsers natively, this is considering that Redmine can now also preview some multimedia formats.


Files

more-mimetypes.patch (956 Bytes) more-mimetypes.patch Anonymous, 2019-09-26 07:40
Actions #1

Updated by Go MAEDA over 4 years ago

  • Target version set to Candidate for next major release
Actions #2

Updated by Go MAEDA over 4 years ago

Maybe we don't have to add .svg, .webp, .ico, .ogg, .wav, and .flac because mini_mime knows them.

[8] pry(main)> MiniMime.lookup_by_filename("a.svg")&.content_type
=> "image/svg+xml" 
[9] pry(main)> MiniMime.lookup_by_filename("a.webp")&.content_type
=> "image/webp" 
[10] pry(main)> MiniMime.lookup_by_filename("a.ico")&.content_type
=> "image/vnd.microsoft.icon" 
[12] pry(main)> MiniMime.lookup_by_filename("a.ogg")&.content_type
=> "audio/ogg" 
[13] pry(main)> MiniMime.lookup_by_filename("a.wav")&.content_type
=> "audio/x-wav" 
[14] pry(main)> MiniMime.lookup_by_filename("a.flac")&.content_type
=> "audio/x-flac" 
Actions #3

Updated by Go MAEDA over 4 years ago

"image/apng" is not a registered media type (https://www.iana.org/assignments/media-types/media-types.xhtml). Instead, we can assign "image/png" to ".apng" extension. I was able to preview an APNG animation with the following change.

Index: lib/redmine/mime_type.rb
===================================================================
--- lib/redmine/mime_type.rb    (リビジョン 18541)
+++ lib/redmine/mime_type.rb    (作業コピー)
@@ -41,7 +41,7 @@
       'text/x-po' => 'po',
       'image/gif' => 'gif',
       'image/jpeg' => 'jpg,jpeg,jpe',
-      'image/png' => 'png',
+      'image/png' => 'png,apng',
       'image/tiff' => 'tiff,tif',
       'image/x-ms-bmp' => 'bmp',
       'application/javascript' => 'js',
Actions #4

Updated by Anonymous over 4 years ago

Go MAEDA wrote:

Maybe we don't have to add .svg, .webp, .ico, .ogg, .wav, and .flac because mini_mime knows them.

It's for attachment media previewing I suppose.

Or else, does helper Redmine::MimeType.is_type?() also uses mini_mime to check the supported mime-type of a file then?

I was working on feature to enable file previews + side by side revision comparison of multimedia binaries in the repository view, so it's already kind-of partially implemented but only for attachments at the moment -> #27336, but it doesn't work in the repo view as of right now.

For some reason, a helper Redmine::MimeType.is_type?() which it seems like, even #27336 relies on, doesn't return any trues on filetypes, unless they are added to mime_type.rb, hence it seems like a preview won't happen unless things are added to mime_type.rb

Or could I otherwise be doing something wrong?

Actions #5

Updated by Anonymous over 4 years ago

Go MAEDA wrote:

"image/apng" is not a registered media type (https://www.iana.org/assignments/media-types/media-types.xhtml). Instead, we can assign "image/png" to ".apng" extension. I was able to preview an APNG animation with the following change.

Yes, thanks for that fix, I used MDN's mime-type list as reference, so hence why I defined it separately.

Actions #6

Updated by Go MAEDA over 4 years ago

Antonio McDeal wrote:

Go MAEDA wrote:

Maybe we don't have to add .svg, .webp, .ico, .ogg, .wav, and .flac because mini_mime knows them.

It's for attachment media previewing I suppose.

Or else, does helper Redmine::MimeType.is_type?() also uses mini_mime to check the supported mime-type of a file then?

Yes. For example, .wav is not included in MIME_TYPES constant, but Redmine::MimeType.is_type? says it is a audio file.

[1] pry(main)> Redmine::MimeType.is_type?('audio', 'a.wav')
=> true

This is because mini_mime is used to determine the media type if the given extension is not included in MIME_TYPES constant. The behavior is implemented in Redmine::MimeType.of.

    def self.of(name)
      ext = File.extname(name.to_s)[1..-1]
      if ext
        ext.downcase!
        EXTENSIONS[ext] || MiniMime.lookup_by_extension(ext)&.content_type
      end
    end
Actions #7

Updated by Go MAEDA over 4 years ago

Antonio McDeal wrote:

I was working on feature to enable file previews + side by side revision comparison of multimedia binaries in the repository view, so it's already kind-of partially implemented but only for attachments at the moment -> #27336, but it doesn't work in the repo view as of right now.

Maybe it is another issue. I confirmed that audio/video preview in the repository browser does not work at all. Please see #32153.

Actions #8

Updated by Go MAEDA about 4 years ago

  • Status changed from New to Closed
  • Target version deleted (Candidate for next major release)

Many of the extension and MIME type combinations added by this patch are already covered by mini_magic.

Actions

Also available in: Atom PDF