{"action":"created","issue":{"url":"https://api.github.com/repos/shrinerb/shrine/issues/283","repository_url":"https://api.github.com/repos/shrinerb/shrine","labels_url":"https://api.github.com/repos/shrinerb/shrine/issues/283/labels{/name}","comments_url":"https://api.github.com/repos/shrinerb/shrine/issues/283/comments","events_url":"https://api.github.com/repos/shrinerb/shrine/issues/283/events","html_url":"https://github.com/shrinerb/shrine/issues/283","id":341480553,"node_id":"MDU6SXNzdWUzNDE0ODA1NTM=","number":283,"title":"How to check and get validation error message for encrypted files","user":{"login":"kashifnaseer","id":1460838,"node_id":"MDQ6VXNlcjE0NjA4Mzg=","avatar_url":"https://avatars3.githubusercontent.com/u/1460838?v=4","gravatar_id":"","url":"https://api.github.com/users/kashifnaseer","html_url":"https://github.com/kashifnaseer","followers_url":"https://api.github.com/users/kashifnaseer/followers","following_url":"https://api.github.com/users/kashifnaseer/following{/other_user}","gists_url":"https://api.github.com/users/kashifnaseer/gists{/gist_id}","starred_url":"https://api.github.com/users/kashifnaseer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kashifnaseer/subscriptions","organizations_url":"https://api.github.com/users/kashifnaseer/orgs","repos_url":"https://api.github.com/users/kashifnaseer/repos","events_url":"https://api.github.com/users/kashifnaseer/events{/privacy}","received_events_url":"https://api.github.com/users/kashifnaseer/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-16T11:23:44Z","updated_at":"2018-07-16T15:39:48Z","closed_at":"2018-07-16T15:39:48Z","author_association":"NONE","body":"In my Application, I want to give an error message when User tries to upload encrypted file. How i can do it using Shrine. \r\n\r\n**Here is my initializer:**\r\n\r\n    require 'shrine'\r\n    require \"cloudinary\"\r\n    require \"shrine/storage/cloudinary\"\r\n\r\n    Shrine.plugin :activerecord\r\n    Shrine.plugin :cached_attachment_data # for forms\r\n    Shrine.plugin :determine_mime_type\r\n    Shrine.plugin :backgrounding\r\n    Shrine.plugin :delete_promoted\r\n\r\n    Shrine::Attacher.promote { |data| PromoteJob.perform_async(data) }\r\n    Shrine::Attacher.delete { |data| DeleteJob.perform_async(data) }\r\n\r\n\r\n**Uploader:**\r\n\r\n    class DocumentUploader < Shrine\r\n      plugin :validation_helpers\r\n      plugin :pretty_location\r\n\r\n      plugin :processing\r\n      plugin :versions\r\n\r\n       Attacher.validate do\r\n        validate_mime_type_inclusion ['application/pdf']\r\n      end\r\n    end\r\n\r\n**model:**\r\n\r\n    class Document < ActiveRecord::Base\r\n      extend Enumerize\r\n      include DocumentUploader::Attachment.new(:doc)\r\n\r\nWhen I create a Document having encrypted file, it should give validation error. How I can do it using shrine ?\r\n"},"comment":{"url":"https://api.github.com/repos/shrinerb/shrine/issues/comments/405290250","html_url":"https://github.com/shrinerb/shrine/issues/283#issuecomment-405290250","issue_url":"https://api.github.com/repos/shrinerb/shrine/issues/283","id":405290250,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNTI5MDI1MA==","user":{"login":"janko-m","id":795488,"node_id":"MDQ6VXNlcjc5NTQ4OA==","avatar_url":"https://avatars2.githubusercontent.com/u/795488?v=4","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":"2018-07-16T15:39:48Z","updated_at":"2018-07-16T15:39:48Z","author_association":"MEMBER","body":"Could you post a self-contained script that reproduces this behaviour (you can find a template in CONTIBUTING.md)? I'm not able to reproduce it myself, for me encrypted files fail validation, here is a script showing that it works:\r\n\r\n```rb\r\nrequire \"active_record\"\r\nrequire \"shrine\"\r\nrequire \"shrine/storage/file_system\"\r\nrequire \"open-uri\"\r\nrequire \"openssl\"\r\n\r\nActiveRecord::Base.establish_connection(adapter: \"sqlite3\", database: \":memory:\")\r\nActiveRecord::Base.connection.create_table(:documents) { |t| t.text :doc_data }\r\n\r\nShrine.storages = {\r\n  cache: Shrine::Storage::FileSystem.new(Dir.tmpdir),\r\n  store: Shrine::Storage::FileSystem.new(Dir.tmpdir),\r\n}\r\n\r\nShrine.plugin :activerecord\r\nShrine.plugin :cached_attachment_data\r\nShrine.plugin :determine_mime_type\r\nShrine.plugin :backgrounding\r\nShrine.plugin :delete_promoted\r\n\r\nShrine::Attacher.promote { |data| Shrine::Attacher.promote(data) } # perform inline\r\nShrine::Attacher.delete { |data| Shrine::Attacher.delete(data) } # perform inline\r\n\r\nclass DocumentUploader < Shrine\r\n  plugin :validation_helpers\r\n  plugin :pretty_location\r\n\r\n  plugin :processing\r\n  plugin :versions\r\n\r\n  Attacher.validate do\r\n    validate_mime_type_inclusion ['application/pdf']\r\n  end\r\nend\r\n\r\nclass Document < ActiveRecord::Base\r\n  include DocumentUploader::Attachment.new(:doc)\r\nend\r\n\r\npdf = open(\"http://gahp.net/wp-content/uploads/2017/09/sample.pdf\")\r\n\r\ndocument = Document.create(doc: pdf)\r\ndocument.valid? # => true\r\n\r\ncipher = OpenSSL::Cipher.new(\"AES-128-CBC\")\r\ncipher.key = \"a\" * 16\r\ncipher.encrypt\r\n\r\nencrypted_pdf = Tempfile.new([\"encrypted\", \".pdf\"], binmode: true)\r\nencrypted_pdf.write cipher.update(File.binread(pdf.path)) + cipher.final\r\nencrypted_pdf.rewind\r\n\r\ndocument = Document.create(doc: encrypted_pdf)\r\ndocument.valid? # => false\r\ndocument.errors.to_h # => {:doc=>\"isn't of allowed type (allowed types: application/pdf)\"}\r\n```\r\n\r\nSince this doesn't appear to be a bug with Shrine, I will close this issue."}}
{"actor":{"display_login":"janko-m"}}