如何通过文件扩展名确定mime类型? (露比) [英] How to determine mime type by the file extension? ( Ruby )

查看:91
本文介绍了如何通过文件扩展名确定mime类型? (露比)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在stackoverflow上看到过类似的问题,但对于ruby来说却一无是处.

I've seen questions like this on stackoverflow but nothing was for ruby.

所以我有这样的文件扩展名:

So I have file extensions like these:

csshtmljsjson

我想将它们转换为:

text/csstext/htmltext/javascriptapplication/json

我想用红宝石实现这一目标.

I want to achieve this in ruby.

因此,在编写此代码之后:

So after writing this:

ext_to_mime("css")

我应该得到:

text/css

如果有任何瑰宝,也欢迎他们.

If there are any gems for this they are also welcome.

推荐答案

您可以使用 mime-types gem:

You could use the mime-types gem:

puts MIME::Types.type_for('css')
  => [text/css]

这篇关于如何通过文件扩展名确定mime类型? (露比)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆