1
votes

I have a product model

#(product.rb):
def get_image_from_link 
unless url.blank?
encoded_url  = URI.encode(url)
self.image  = URI.parse(url)
end

With the following validations:

validates_attachment_content_type :image, content_type: /\Aimage/
validates_attachment_file_name :image, matches: [/png\Z/, /jpe?g\Z/]

I am parsing some thousands of URLs to Paperclip 4.0. Paperclip is not saving the image and the name in the database for some of the URLs.

Problem is, I cannot see any error and I cannot see the answer from the problematic urls. Instead of writing the SQL back it states ROLLBACK. Any idea?

This URL would work: http://i.stylepit.com/common/225162/33/225162_1_2_33.jpg This URL would not work: http://lsco.scene7.com/is/image/lsco/Levi/clothing/658190078-front-grid.jpg

Here the rails log:

Product Load (12.5ms)  SELECT `products`.* FROM `products`  WHERE (`products`.`id` BETWEEN 6543 AND 16640)
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/54c9b33af60ed43f767d65879eef4ae520160125-89544-1ng82hf.jpg[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/54c9b33af60ed43f767d65879eef4ae520160125-89544-1ng82hf.jpg[0]'
Command :: convert '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/54c9b33af60ed43f767d65879eef4ae520160125-89544-1ng82hf.jpg[0]' -auto-orient -resize "500x600!" '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/3cabc5720daa884aae0baca2b9deff8620160125-89544-d33v1w'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/54c9b33af60ed43f767d65879eef4ae520160125-89544-1ng82hf.jpg[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/54c9b33af60ed43f767d65879eef4ae520160125-89544-1ng82hf.jpg[0]'
Command :: convert '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/54c9b33af60ed43f767d65879eef4ae520160125-89544-1ng82hf.jpg[0]' -auto-orient -resize "300x400!" '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/3cabc5720daa884aae0baca2b9deff8620160125-89544-opiint'
   (0.2ms)  BEGIN
  Product Exists (7.6ms)  SELECT  1 AS one FROM `products`  WHERE (`products`.`slug` = BINARY '606557062827' AND `products`.`id` != 6543) LIMIT 1
   (0.2ms)  ROLLBACK
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/abd8cc1fc2c7b161afbe4bd1cf9793b720160125-89544-1xboc34.jpg[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/abd8cc1fc2c7b161afbe4bd1cf9793b720160125-89544-1xboc34.jpg[0]'
Command :: convert '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/abd8cc1fc2c7b161afbe4bd1cf9793b720160125-89544-1xboc34.jpg[0]' -auto-orient -resize "500x600!" '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/2185eefda52e42bea24b1207c03ca9a420160125-89544-1i2c9ku'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/abd8cc1fc2c7b161afbe4bd1cf9793b720160125-89544-1xboc34.jpg[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/abd8cc1fc2c7b161afbe4bd1cf9793b720160125-89544-1xboc34.jpg[0]'
Command :: convert '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/abd8cc1fc2c7b161afbe4bd1cf9793b720160125-89544-1xboc34.jpg[0]' -auto-orient -resize "300x400!" '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/2185eefda52e42bea24b1207c03ca9a420160125-89544-1w7jcw8'
   (0.2ms)  BEGIN
  Product Exists (5.6ms)  SELECT  1 AS one FROM `products`  WHERE (`products`.`slug` = BINARY '738372485742' AND `products`.`id` != 6550) LIMIT 1
   (0.2ms)  ROLLBACK
^C[2016-01-25 13:52:16] INFO  going to shutdown ...
^CCommand :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/d333c5315c2c15bc42bdd50421924c1420160125-89544-mvcfe7.jpg[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/d333c5315c2c15bc42bdd50421924c1420160125-89544-mvcfe7.jpg[0]'
Command :: convert '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/d333c5315c2c15bc42bdd50421924c1420160125-89544-mvcfe7.jpg[0]' -auto-orient -resize "500x600!" '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/10f8983119040bef062a26410feb02a420160125-89544-fk9653'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/d333c5315c2c15bc42bdd50421924c1420160125-89544-mvcfe7.jpg[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/d333c5315c2c15bc42bdd50421924c1420160125-89544-mvcfe7.jpg[0]'
Command :: convert '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/d333c5315c2c15bc42bdd50421924c1420160125-89544-mvcfe7.jpg[0]' -auto-orient -resize "300x400!" '/var/folders/vw/7dfpgzk12bq2rvyt0xf43n_w0000gn/T/10f8983119040bef062a26410feb02a420160125-89544-l1ol9t'
   (0.1ms)  BEGIN
  Product Exists (3.4ms)  SELECT  1 AS one FROM `products`  WHERE (`products`.`slug` = BINARY '609421259727' AND `products`.`id` != 6557) LIMIT 1
   (2.1ms)  ROLLBACK

Controller actions:

before_action :set_product, only: [:show, :edit, :update, :destroy] 

Schema:

create_table "products", force: true do |t| t.string "title" t.text "description", limit: 2147483647 t.string "shop_id", limit: 128 t.string "color_id" t.string "size_id" t.string "brand_id" t.text "url", limit: 2147483647 t.datetime "created_at" t.datetime "updated_at" t.string "image_file_name" t.string "image_content_type" t.integer "image_file_size" t.datetime "image_updated_at"

Product Params:

def params.require(:product).permit(:title, :description, :size_id, :category3, :oldprice, :newprice, :color_id, :brand_id, :image, :image2, :image3, :category_id [])

1
Are you permitting your params correctly?Richlewis
Could you show your schema and controller actions for the file upload pleaseRichlewis
you could just update your question with these please, very difficult to read as a commentRichlewis
try content_type: { :content_type => ['image/jpg', 'image/jpeg', 'image/gif', 'image/png'] as your validation for nowRichlewis
with that validation nothing gets processed even the old links do not work any longer.Karsten

1 Answers

0
votes

Problem was params. Not all fields in the database were filled. Therefore no file downloaded and saved by paperclip.

Thanks for your help!