Paperclip 4.0无法保存图像和名称

时间:2016-01-25 13:25:53

标签: ruby-on-rails paperclip

我有一个产品型号

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

通过以下验证:

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

我正在将数千个URL解析为Paperclip 4.0。 Paperclip不会在数据库中为某些URL保存图像和名称。

问题是,我看不到任何错误,我无法从有问题的网址看到答案。它没有写回SQL,而是表示ROLLBACK。有什么想法吗?

此网址有效: http://i.stylepit.com/common/225162/33/225162_1_2_33.jpg 此网址无效: http://lsco.scene7.com/is/image/lsco/Levi/clothing/658190078-front-grid.jpg

这里有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

控制器操作:

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

架构:

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"

产品参数:

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

1 个答案:

答案 0 :(得分:0)

问题是障碍。并非所有数据库中的字段都已填充。因此,没有文件由回形针下载和保存。

感谢您的帮助!