{"action":"created","issue":{"url":"https://api.github.com/repos/janko-m/shrine/issues/133","repository_url":"https://api.github.com/repos/janko-m/shrine","labels_url":"https://api.github.com/repos/janko-m/shrine/issues/133/labels{/name}","comments_url":"https://api.github.com/repos/janko-m/shrine/issues/133/comments","events_url":"https://api.github.com/repos/janko-m/shrine/issues/133/events","html_url":"https://github.com/janko-m/shrine/issues/133","id":202494637,"number":133,"title":"validation_helpers doesn't get the mime_type","user":{"login":"R4ttlesnake","id":25295954,"avatar_url":"https://avatars.githubusercontent.com/u/25295954?v=3","gravatar_id":"","url":"https://api.github.com/users/R4ttlesnake","html_url":"https://github.com/R4ttlesnake","followers_url":"https://api.github.com/users/R4ttlesnake/followers","following_url":"https://api.github.com/users/R4ttlesnake/following{/other_user}","gists_url":"https://api.github.com/users/R4ttlesnake/gists{/gist_id}","starred_url":"https://api.github.com/users/R4ttlesnake/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/R4ttlesnake/subscriptions","organizations_url":"https://api.github.com/users/R4ttlesnake/orgs","repos_url":"https://api.github.com/users/R4ttlesnake/repos","events_url":"https://api.github.com/users/R4ttlesnake/events{/privacy}","received_events_url":"https://api.github.com/users/R4ttlesnake/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-01-23T10:21:28Z","updated_at":"2017-01-28T00:11:01Z","closed_at":null,"body":"Hi,\r\nI'm using the validation_helpers plugin to validate the size and mime-type of my upload. Running a model spec without the mime-type validation, the spec passes. With the mime-type validation and any image-file I try, the validation fails. \r\n\r\nChecking the mime type of the test-file in my terminal says _image/jpeg_. I tried checking the mime-type with `puts get.mime_type` in the Attacher block, but it only returns an empty line in the terminal.\r\n\r\nDo you know how to solve this (below my code)?\r\n\r\nThanks\r\n\r\nps: There is a typo on the [validation_helpers docs](http://shrinerb.com/rdoc/classes/Shrine/Plugins/ValidationHelpers.html). In the first code block it says _validat_mime_type_inclusion_, it should probably be _validate_mime_type_inclusion_.\r\n\r\nuploaders/image_uploader:\r\n```\r\nAttacher.validate do\r\n  puts get.mime_type # returns empty strings\r\n  validate_mime_type_inclusion %w[image/jpeg image/png image/gif]\r\n  validate_max_size 4.megabyte, message: \"your file is too large (max. 4MB)\"\r\nend\r\n```\r\n\r\ninitializers/shrine.rb:\r\n```\r\nrequire 'shrine'\r\nrequire 'shrine/storage/file_system'\r\nrequire 'shrine/storage/memory'\r\n\r\nif Rails.env.test?\r\n  Shrine.storages = {\r\n    cache: Shrine::Storage::Memory.new,\r\n    store: Shrine::Storage::Memory.new,\r\n  }\r\nelse\r\n  Shrine.storages = {\r\n    cache: Shrine::Storage::FileSystem.new('public', prefix: 'uploads/cache'),\r\n    store: Shrine::Storage::FileSystem.new('public', prefix: 'uploads/store'),\r\n  }\r\nend\r\n\r\nShrine.plugin :activerecord\r\nShrine.plugin :cached_attachment_data\r\nShrine.plugin :logging, logger: Rails.logger\r\n```\r\n\r\nspec:\r\n```\r\n# valid without validate_mime_type_inclusion\r\n# invalid with validate_mime_type_inclusion\r\nexhibition.image = File.open(File.join(Rails.root, 'spec/support/test_files/haruki.jpg'))\r\nexpect(exhibition).to be_valid\r\n```"},"comment":{"url":"https://api.github.com/repos/janko-m/shrine/issues/comments/275808217","html_url":"https://github.com/janko-m/shrine/issues/133#issuecomment-275808217","issue_url":"https://api.github.com/repos/janko-m/shrine/issues/133","id":275808217,"user":{"login":"janko-m","id":795488,"avatar_url":"https://avatars.githubusercontent.com/u/795488?v=3","gravatar_id":"","url":"https://api.github.com/users/janko-m","html_url":"https://github.com/janko-m","followers_url":"https://api.github.com/users/janko-m/followers","following_url":"https://api.github.com/users/janko-m/following{/other_user}","gists_url":"https://api.github.com/users/janko-m/gists{/gist_id}","starred_url":"https://api.github.com/users/janko-m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/janko-m/subscriptions","organizations_url":"https://api.github.com/users/janko-m/orgs","repos_url":"https://api.github.com/users/janko-m/repos","events_url":"https://api.github.com/users/janko-m/events{/privacy}","received_events_url":"https://api.github.com/users/janko-m/received_events","type":"User","site_admin":false},"created_at":"2017-01-28T00:11:01Z","updated_at":"2017-01-28T00:11:01Z","body":"Could you also post your uploader code? The metadata extraction is a separate process from validations, the `validation_helpers` doesn't affect the MIME type extracted in any way, it just provides helper methods for validating the values that were already extracted.\r\n\r\nNote that by default Shrine will only populate the `mime_type` metadata if the given file responds to `#content_type`. The `ActionDispatch::Http::UploadedFile` in the Rails controller (or file assigned by the `rack_file` plugin) responds to `#content_type`, populated from the `Content-Type` request header, so Shrine simply copies that value over as `mime_type`.\r\n\r\nShrine won't automatically try to determine the MIME type from extension or file contents, because it doesn't know which library you would like to use (`mime-types`, `file` utility, `mimemagic`, `ruby-filemagic`, or something else). In order to extract the actual MIME type from any IO object you need load the `determine_mime_type` plugin.\r\n\r\n```\r\nplugin :determine_mime_type\r\n```"}}
{"actor":{"display_login":"janko-m"}}