Paperclip :: Error,处理缩略图时出错

时间:2015-06-01 10:50:34

标签: ruby-on-rails amazon-s3 paperclip aws-sdk

我正在使用paperclip,imagemagick,rmagick将图像上传到s3。以前,图片上传功能在ruby 1.9.3'rails', '3.2.11'上运行良好。升级ruby 2.0.0'rails', '4.0.3'之后,将其彻底改错。

在store.rb

#paperclip
has_attached_file :logo,
styles: {
  thumb: ["40x40#", :png],
  small: ["400x400>", :png],
  masked_with_overlay: ["288x64", :png],
  masked_with_nearby_overlay: ["238x47#", :png],
  masked_with_rewards_overlay: ["288x64", :png],
  masked_with_overlay_for_old: ["288x64", :png],
  masked_with_nearby_overlay_for_old: ["238x47#", :png],
  masked_with_rewards_overlay_for_old: ["288x64", :png],
  masked_full_card_image: ["576x128", :png],
  masked_logo_only: ["576x128", :png]
},
convert_options: { masked_with_overlay: Proc.new{self.apply_mask_and_overlay},
  masked_with_nearby_overlay: Proc.new{self.apply_mask_and_nearby_overlay},
  masked_with_rewards_overlay: Proc.new{self.apply_mask_and_rewards_overlay},
  masked_with_overlay_for_old: Proc.new{self.apply_mask_and_overlay_for_old},
  masked_with_rewards_overlay_for_old: Proc.new{self.apply_mask_and_rewards_overlay_for_old},
  masked_full_card_image: Proc.new{self.apply_mask_full_card_image},
  masked_logo_only: Proc.new{self.apply_mask_logo_only}

},
storage: :s3,
s3_credentials: "#{Rails.root}/config/s3.yml",
path: "/store_logos/:style/:id/:filename"

validates_attachment :logo, content_type: { content_type: ["image/jpg", "image/jpeg", "image/png", "image/JPG", "image/JPEG", "image/PNG"] }

这里是Gemfile

ruby '2.0.0'
gem 'rails', '4.0.3'
gem 'aws-s3'
gem 'aws-sdk', '~> 1.5.7'
gem 'paperclip', "~> 4.2"
gem 'rmagick', '2.13.2'

stores_controller.rb

class StoresController < ApplicationController
  def update

   if !params[:store].nil? && !params[:store][:store_owner].nil?
    params[:store][:store_owner][:email] = params[:store][:store_owner][:email].downcase
   end

   if params[:demo_store_changes]
     params[:store][:active] = false
   else
     params[:store][:store_hours] = params[:store][:store_hours].to_json
     params[:store][:minimum_seconds_per_scan] = (params[:store][:minimum_seconds_per_scan]).to_i * 3600
   end

  @store.store_owner.store_owner!

  if params[:store][:scanning_distance].blank?
    params[:store].delete :ms
  else
    if params[:store][:location_check]
      if params[:store][:ms] == "mi"
        params[:store][:scanning_distance] = ( params[:store][:scanning_distance].to_f * 5280 )
        params[:store].delete :ms
      else
        params[:store][:scanning_distance] = params[:store][:scanning_distance].to_f
        params[:store].delete :ms
      end
    end
  end

  if @store.update_attributes(store_params) and @store.build_categories(params[:category_ids].to_a)
   if params[:demo_store_changes]
     demo_message = @store.demo ? " is now demo store" : " is not a demo store anymore"
     flash[:notice] = @store.name + demo_message
     redirect_to stores_path('store[search]'=> params[:store_search], search_value: params[:search_value])
   else
     @password_chk=params[:store][:store_owner_attributes][:password] 
     redirect_to "#{store_path()}?myid=#{session[:bread_crum]}", notice: (I18n.t :update_store_success)
   end
 else
   @store.store_hours = ActiveSupport::JSON.decode(@store.store_hours)
   if @store.minimum_seconds_per_scan?
     @store.minimum_seconds_per_scan = (@store.minimum_seconds_per_scan / 3600).to_i
   end
   @categories = Category.all.sort
   @states = StoreConstants::STATES.sort
   @main_location_stores = Store.with_no_branch(@store.id)
   flash.now[:error] = (I18n.t :update_store_failed)
   render action: "edit"
 end

 private
 def store_params
   params.require(:store).permit!
 end
end

这是log

任何帮助?,提前致谢

2 个答案:

答案 0 :(得分:0)

查看日志 (:bucket_name =&gt;&#34; punchme-co-dev&#34;,:key =&gt;&#34; store_logos / masked_with_rewards_overlay / 96 / Casablanca.png&#34;)AWS :: S3 :: Errors :: NoSuchKey没有这样的钥匙) AWS访问密钥正在获取您的图像文件路径。

答案 1 :(得分:0)

我终于找到了解决方案。

convert: no decode delegate for this image format `/home/likewise-open/ANNETSITE/1820/RailsWorkspace/Punchme_web_Test' @ error/constitute.c/ReadImage/532.
convert: unable to open image `Builds/app/assets/images/card_overLay.png':  @ error/blob.c/OpenBlob/2587.

通过将项目文件夹Project_web_Test Builds重命名为Project_web_Test_Builds,不允许处理图像空间。