Gitlab (rails) "raw" file mime type for .svg files is 'text/plain'. Can it be configured to output as 'image/svg+xml'?
Found it. seems the content type is set in ruby code in the raw_controller.rb file. so i edit
/opt/gitlab/embedded/service/gitlab-rails/app/controllers/projects/raw_controller.rb
change this:
def get_blob_type
if @blob.text?
'text/plain; charset=utf-8'
else
'application/octet-stream'
end
end
to something like this:
def get_blob_type
extn = File.extname(@blob.name).downcase
if @blob.text?
if extn == ".svg"
'image/svg+xml'
else
'text/plain; charset=utf-8'
end
else
case extn
when ".jpg", ".jpeg"
'image/jpeg'
when ".gif"
'image/gif'
when ".png"
'image/png'
when ".bmp"
'image/bmp'
when ".tiff"
'image/tiff'
else
'application/octet-stream'
end
end
end
then sudo gitlab-ctrl restart
now in my markdown, if i do this:
![my-diagram](http://server/my-group/my-project/raw/master/docsfolder/my-drawing.svg)
it works!
I've never used ruby before, so maybe there's a better way, but so far works for me.
101chris's proposal works fine on 7.x, but needs some rework on gitlab 8.x. Here's my update tested on 8.14.4:
/opt/gitlab/embedded/service/gitlab-rails/app/helpers/blob_helper.rb :
def safe_content_type(blob)
if blob.text?
case File.extname(blob.name).downcase
when '.html'
'text/html'
when '.css'
'text/css'
when '.xml'
'text/xml'
when '.js'
'application/javascript'
else
'text/plain; charset=utf-8'
end
elsif blob.image?
blob.content_type
else
'application/octet-stream'
end
end