ruby - Rails Paperclip skip upload if image is already present -


im trying import of thousands of items , of them use same image. want check before uploading image if 1 exists same name can save time , resources. using amazon s3 storage. cant seem find in documentation it. know can image.exists? do in model not upload image still set in database point existing image.

rails 3.2.12
paperclip 3.2.1

validates_attachment_content_type :image, :content_type => ['image/jpeg', 'image/png', 'image/gif', 'image/pjpeg']  has_attached_file :image,                 :storage => :s3,                 :s3_credentials => "#{rails.root.to_s}/config/s3.yml",                 :path => "images/:attachment/:style/:filename",                 :styles => { :original => '64x64', :small => '32x32' } 

i've run exact problem before well, , never found solution this. think it's because of design of paperclip every record needs unique attachment.

you try copying existing attachment record, still upload "copied" attachment record.

the best alternative find (without forking , trying monkeypatch paperclip) move processing of attaching files background job, resque. offload time part of concern. resources, s3 pretty cheap - i've never been above $0.15 s3 instance hundreds of thousands of images, it's site doesn't traffic.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -