line-bot-sdk-ruby icon indicating copy to clipboard operation
line-bot-sdk-ruby copied to clipboard

Correct the solution to get the content type

Open yopaz-giapnh opened this issue 4 years ago • 1 comments

https://github.com/line/line-bot-sdk-ruby/blob/147323c29a2b680204f8bf186d82d146ebaff468/lib/line/bot/client.rb#L1078-L1083

If using the file with no extension, this caused an error. For eg: "/var/folders/m3/p364c0313fv0mhbl3llm4bvw0000gp/T/ActiveStorage-27-20210918-49325-1bu8npn"

yopaz-giapnh avatar Sep 18 '21 10:09 yopaz-giapnh

You're right, It's too difficult to use for content_type detection. But you can use the following method to get the content_type of the file instead of the file extension.

irb> file = open('https://www.ruby-lang.org/images/header-ruby-logo.png')
irb> file.content-type
=> "image/png"

https://github.com/line/line-bot-sdk-ruby/blob/147323c29a2b680204f8bf186d82d146ebaff468/lib/line/bot/client.rb#L1072-L1076

But this use case is required use open-uri :( https://ruby-doc.org/stdlib-2.5.1/libdoc/open-uri/rdoc/OpenURI/Meta.html#method-i-content_type

In my opinion, I think it would be good to be able to pass the content_type as an argument.

kimoto avatar Sep 21 '21 10:09 kimoto