简体   繁体   English

回形针4.0不保存图像和名称

[英]Paperclip 4.0 does not save image and name

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 4.0的URL。 Paperclip is not saving the image and the name in the database for some of the URLs. 回形针没有将某些URL的图像和名称保存在数据库中。

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. 它没有回写SQL,而是显示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 该URL将起作用: http : //i.stylepit.com/common/225162/33/225162_1_2_33.jpg此URL将不起作用: http : //lsco.scene7.com/is/image/lsco/Levi/clothing/ 658190078-前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 []) def params.require(:product).permit(:title,:description,:size_id,:category3,:oldprice,:newprice,:color_id,:brand_id,:image,:image2,:image3,:category_id [])

Problem was params. 问题是参数。 Not all fields in the database were filled. 并非数据库中的所有字段都已填写。 Therefore no file downloaded and saved by paperclip. 因此,没有文件通过回形针下载和保存。

Thanks for your help! 谢谢你的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM