DavyJonesLocker / client_side_validations

Client Side Validations made easy for Ruby on Rails
MIT License
2.69k stars 403 forks source link

Validating size of file #502

Closed travisvalentine closed 11 years ago

travisvalentine commented 11 years ago

I see in the wiki that there is a way to validate_presence_of a file uploaded with Paperclip, but was wondering if there was a way to validate the file's size.

maintux commented 11 years ago

Checking file size client side, at the moment isn't supported by all browser, so this kind of validation won't work everywhere. Check this for more details http://caniuse.com/#feat=fileapi Anyway can be a future implementation.

bcardarella commented 11 years ago

Out of the box client side validations is only meant to include the validations that are present in Rails core. This particular validation is not part of Rails so it would be subject to a plugin. Someone could create client_side_validations-paperclip that would include the file validation or perhaps a more general client_side_validations-attachment that would work with both Paperclip and Carrierwave. I'll close this as it is not an issue with ClientSideValidations but I am happy to continue the conversation.

travisvalentine commented 11 years ago

Ah right, makes sense. Thanks for the prompt reply.

eliotsykes commented 7 years ago

Just highlighting this for developers searching for Paperclip and client side validations for attachment file size and Content-Type, check out the wiki page section: https://github.com/DavyJonesLocker/client_side_validations/wiki/Paperclip#size-and-content-validation

tagliala commented 7 years ago

@eliotsykes thanks

Since CSV is supposed to support IE >= 8, could you please clarify browser compatibility and that developer is supposed to implement an alternative way to load it without turbolinks?

eliotsykes commented 7 years ago

Hi @tagliala - thanks that section has been there a long time, not written by me. I added notes today that's all. I'll add what I can from what you suggested.

tagliala commented 7 years ago

Thanks.

size: { in: 0..10.megabytes }

Does this work? I'm seeing that javascript only checks for less_than_or_equal_to

eliotsykes commented 7 years ago

@tagliala - that wouldn't work as is, nor would less_than or the other possible options, it'd need modifying. I've adjusted the original code snippets to similar to what I'm using locally. Its now using less_than, and this would not work with other options, it would need further modification.