Paperclip problem when re-generating thumbs

I'm trying to recreate all the thumbs. I am not sure why it is said that the key does not exist. My AWS-S3 is configured correctly and it works well (I can upload pictures without a problem.)

>> Attachment.all.each {|x|x.attachment.reprocess!} AWS::S3::NoSuchKey: The specified key does not exist. /app/d999782b-a789-4763-ac86-e8c65fa781eb/home/.bundle/gems/ruby/1.8/gems/aws-s3- 0.6.2/lib/aws/s3/error.rb:38:in `raise' /app/d999782b-a789-4763-ac86-e8c65fa781eb/home/.bundle/gems/ruby/1.8/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:72:in `request' /app/d999782b-a789-4763-ac86-e8c65fa781eb/home/.bundle/gems/ruby/1.8/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:88:in `get' /app/d999782b-a789-4763-ac86-e8c65fa781eb/home/.bundle/gems/ruby/1.8/gems/aws-s3-0.6.2/lib/aws/s3/object.rb:134:in `value' 

When I tried to do the same thing with a single object, it seems to work well, so the problem seems to be related to generating via collection.

 >> Attachment.last.attachment.reprocess! => true 

UPDATE: I am sure this is due to the fact that there are uploaded files, such as .htm, which must be valid image files. Any idea how to skip them?

+4
source share
5 answers

Although I'm not sure, but hope this can help you.

 Attachment.all.each { |x| x.attachment.reprocess! if ['.jpeg','.jpg','.png','.gif'].include?(File.extname(file_name))} 

where file_name => Name of the uploaded file

Best of luck

+9
source

Not sure where you placed your key for AWS-S3, but you may need to specify that you want to run it in a production environment.

 heroku rake paperclip:refresh CLASS=Attachment RAILS_ENV=production 
+7
source

I don’t know how your checks are set up, but is it possible that some attachment objects may have a loose attachment? If yes, try:

 Attachment.all.each { |x| x.attachment.reprocess! rescue nil } 
+1
source

This error may also mean that the object (key) no longer exists on S3, but you have an entry pointing to it in your database. This only happens if someone has made changes to the S3 bucket, which is not related to what you have in your database.

If this is the case, can you use ".exists"? A method in the application to check if this key exists on the Amazon server, and not that it will issue a read request.

This will change your reprogramming command to something like this:

Attachment.all.each { |x| x.attachment.reprocess! if x.attachment.exists? }

+1
source

Do you consider using:

 rake paperclip:refresh 

Instead

0
source

Source: https://habr.com/ru/post/1342214/


All Articles