Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

contradictory wiki / readme about preprocessing invalid too-large files #2236

Closed
nruth opened this issue Jun 22, 2016 · 5 comments · Fixed by kreeti/kt-paperclip#16
Closed

Comments

@nruth
Copy link

nruth commented Jun 22, 2016

https://github.com/thoughtbot/paperclip#validations says

NOTE: Post-processing will not even start if the attachment is not valid according to the validations. Your callbacks and processors will only be called with valid attachments.

https://github.com/thoughtbot/paperclip/wiki/Thumbnail-Generation#prevent-thumbnail-generation-for-invalid-uploads says

h2. Prevent thumbnail generation for invalid uploads

If you upload a file that is too large or otherwise doesn't fit the requirements, paperclip still processes all styles during assignment before the model object is recognized as invalid during @#save@. This can be a huge waste of time if you're working with big files and/or many styles.

You can use a @before_post_process@ filter to avoid post processing. For example, if your attribute is named @image@, and you have a restriction on the file size, the filter could look like this:

before_post_process :check_file_size
def check_file_size
  valid?
  errors[:image_file_size].blank?
end

Which is correct?
Is the wiki text now outdated and deletable?

@tute
Copy link
Contributor

tute commented Jun 22, 2016

The README is incorrect. See PR: #2204. Thanks for bringing this up.

@nruth
Copy link
Author

nruth commented Jun 25, 2016

OK, what can we do to close this issue? Will that PR fix the inconsistency, or is it worth changing the text in the readme?

@tute
Copy link
Contributor

tute commented Jul 1, 2016

Just commented on the PR: adjusting the README to describe current behavior is a first step, indeed! #2204 (comment)

Thank you for reporting.

saghaulor added a commit to saghaulor/paperclip that referenced this issue Apr 26, 2018
- Because the processors were called on assignment, instead of during saving,
  the validations could never work correctly. This is because the built in
  validations use the values in the db columns to operate. However, since these
  are populated on assignment, the validations cannot run before the processors
  run. Moreover, any other type of validation not dependent on the db columns
  also cannot run, because the processors are called on assignment. The
  processors should be called during save which allows for validations to occur.

- Fixed tests that assert the incorrect behavior

- Closes thoughtbot#2462, Closes thoughtbot#2321, Closes
  thoughtbot#2236, Closes thoughtbot#2178,
  Closes thoughtbot#1960, Closes thoughtbot#2204
@sidraval
Copy link
Contributor

Open PR that will be merged, thanks for the issue.

saghaulor added a commit to saghaulor/paperclip that referenced this issue Aug 19, 2018
- Because the processors were called on assignment, instead of during saving,
  the validations could never work correctly. This is because the built in
  validations use the values in the db columns to operate. However, since these
  are populated on assignment, the validations cannot run before the processors
  run. Moreover, any other type of validation not dependent on the db columns
  also cannot run, because the processors are called on assignment. The
  processors should be called during save which allows for validations to occur.

- Fixed tests that assert the incorrect behavior

- Closes thoughtbot#2462, Closes thoughtbot#2321, Closes
  thoughtbot#2236, Closes thoughtbot#2178,
  Closes thoughtbot#1960, Closes thoughtbot#2204
@ssinghi
Copy link

ssinghi commented Dec 30, 2019

This has been fixed at https://github.com/kreeti/paperclip/commits/master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants