{"action":"created","issue":{"url":"https://api.github.com/repos/refile/refile/issues/174","labels_url":"https://api.github.com/repos/refile/refile/issues/174/labels{/name}","comments_url":"https://api.github.com/repos/refile/refile/issues/174/comments","events_url":"https://api.github.com/repos/refile/refile/issues/174/events","html_url":"https://github.com/refile/refile/issues/174","id":60781905,"number":174,"title":"File size validation","user":{"login":"5t111111","id":333180,"avatar_url":"https://avatars.githubusercontent.com/u/333180?v=3","gravatar_id":"","url":"https://api.github.com/users/5t111111","html_url":"https://github.com/5t111111","followers_url":"https://api.github.com/users/5t111111/followers","following_url":"https://api.github.com/users/5t111111/following{/other_user}","gists_url":"https://api.github.com/users/5t111111/gists{/gist_id}","starred_url":"https://api.github.com/users/5t111111/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/5t111111/subscriptions","organizations_url":"https://api.github.com/users/5t111111/orgs","repos_url":"https://api.github.com/users/5t111111/repos","events_url":"https://api.github.com/users/5t111111/events{/privacy}","received_events_url":"https://api.github.com/users/5t111111/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-12T07:39:48Z","updated_at":"2015-03-12T08:24:23Z","closed_at":null,"body":"While I'm sure it's controversial if file size in metadata is reliable like #100, I think file size validation is still   a good feature for convenience.\r\n\r\nSo I've roughly monkey-patched `valid?` of `Attacher` class.\r\n\r\n```ruby\r\nmodule Refile\r\n  class Attacher\r\n    def valid?\r\n      @errors = []\r\n      @errors << :invalid_extension if valid_extensions and not valid_extensions.include?(extension)\r\n      @errors << :invalid_content_type if valid_content_types and not valid_content_types.include?(content_type)\r\n      @errors << :exceeds_allowed_size if @metadata[:size] and @metadata[:size] > 1024 * 1024 # file size should be within 1MB\r\n      @errors << :too_large if cache.max_size and size and size >= cache.max_size\r\n      @errors.empty?\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nI'd like to know if there's better way to validate the size of the file to be uploaded or if you are planning to add file type validation feature."},"comment":{"url":"https://api.github.com/repos/refile/refile/issues/comments/78439830","html_url":"https://github.com/refile/refile/issues/174#issuecomment-78439830","issue_url":"https://api.github.com/repos/refile/refile/issues/174","id":78439830,"user":{"login":"jnicklas","id":134,"avatar_url":"https://avatars.githubusercontent.com/u/134?v=3","gravatar_id":"","url":"https://api.github.com/users/jnicklas","html_url":"https://github.com/jnicklas","followers_url":"https://api.github.com/users/jnicklas/followers","following_url":"https://api.github.com/users/jnicklas/following{/other_user}","gists_url":"https://api.github.com/users/jnicklas/gists{/gist_id}","starred_url":"https://api.github.com/users/jnicklas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jnicklas/subscriptions","organizations_url":"https://api.github.com/users/jnicklas/orgs","repos_url":"https://api.github.com/users/jnicklas/repos","events_url":"https://api.github.com/users/jnicklas/events{/privacy}","received_events_url":"https://api.github.com/users/jnicklas/received_events","type":"User","site_admin":false},"created_at":"2015-03-12T08:24:23Z","updated_at":"2015-03-12T08:24:23Z","body":"We already have validation of size, simply set `max_size` in your backend. It's the line below the one you added ;)"}}