开发者

Detecting file type

What is the best way to find the file mime type of remote file in ruby on rails application (eg. I have a file located in s3 and want to check its file type, I don't 开发者_开发知识库think checking extension of file is a good idea).

To be specific, I want to find whether the given media is video or audio.


There's a library called ruby-filemagic that can check the content of the file and return the mime type. However, it required to access and read the file and it can be an issue if you need to fetch the content of the file from a remote source.

Please note that in the specific Amazon S3 case, you can also store the mime type of the file to Amazon S£ as object metadata when you upload the file itself. I strongly recommend you to do this, so that you can easily retrieve the metadata and search for the given attribute, instead of guessing it from the file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜