Tag: 回形针

如何根据用户性别和资产风格设置Paperclip:default_url?

通过这个gist脚本,我可以获得具有用户性别的回形针的默认URL。 但我想得到:风格也是如此。 有人知道怎么做?

回形针锐化处理器导致调整样式不起作用

我正在尝试锐化通过回形针上传的图像。 锐化代码正在工作,但它导致样式不起作用。 代码是这样的: has_attached_file :photo, :styles => { :thumb => {:geometry => “100×100>”}, :medium => {:geometry => “300×300>”}, :original => {:geometry => “1024×1024>”} }, :processors => [:sharpen], :storage => :s3, :s3_credentials => “#{Rails.root}/config/s3.yml”, :path => “/:style/:id/:filename” 现在,如果我删除处理器选项,则按指定调整上传的图像大小。 但是,如果我包含处理器选项,则所有生成的图像都具有原始大小。 我的锐化处理器看起来像这样: module Paperclip class Sharpen < Paperclip::Processor def initialize file, options = {}, attachment = nil super […]

Rails Paperclip与模型关联

我有一个页面,我可以在其中查看产品,并且可以直接从该页面添加和删除与产品关联的多个图像。 我在表单中使用paperclip来上传新文件。 因为可以为产品保存多个图像,所以我创建了属于产品模型的图像模型。 由于关联,无法使用默认回形针文件输入。 下面我的解决方案正在运行,但我想知道是否有更好的方法在rails中完成此操作而没有我所黑的所有html使其工作。 class Image < ActiveRecord::Base belongs_to :product class Product < ActiveRecord::Base has_many :images, :dependent => :destroy accepts_nested_attributes_for :images, :allow_destroy => true show.html.erb { :multipart => true }) do |f| %> <input id="image" name="product[images_attributes][][photo]” >size=”30″ type=”file” onchange=”this.form.submit();” />

创建用于删除属于产品的上传的表单

我使用基于此应用程序https://github.com/websymphony/Rails3-Paperclip-Uploadify的回形针进行了多次上传,并且它工作正常,但现在我需要构建一个表单,用户可以删除部分上传内容。 我有这个表格来删除一个产品的上传 { :method => :put }, :html => { :multipart => true } do |f| %> ‘checkbox’ %> Delete item 这个表单以某种方式显示正确的上传号码,我可以在终端窗口中看到所有上传产品都带有product_id = product.id,但是我没有在页面中显示图像,如图所示: 终奌站 Started GET “/admin/products/40” for 127.0.0.1 at Tue Apr 10 10:20:06 +0300 2012 Processing by Admin::ProductsController#show as HTML Parameters: {“id”=>”40”} Creating scope :page. Overwriting existing method AdminUser.page. AdminUser Load (2.4ms) SELECT […]

S3上的回形针处理器超时

我正在将数字签名插入到处理器内的pdf文件中,但不断收到AWS::S3::ERRORS::Requestimeout错误。 什么是超时? 有没有什么办法可以保持连接打开,直到文件上传? 未在超时期限内读取或写入与服务器的套接字连接。 空闲连接将被关闭。 这是我的代码: 模型: … has_attached_file :receipt_file, :storage => :s3, :s3_credentials => “#{Rails.root}/config/s3.yml”, :path => “/:style/:id/:filename”, :s3_protocol => “https”, :styles => {dummy:””}, processors: [:SignPdf] #process_in_background :receipt_file … 处理器 module Paperclip class SignPdf < Processor attr_accessor :receipt_id,:style S3_CONFIG = YAML.load_file("#{::Rails.root}/config/s3.yml")[Rails.env] ORIGAMIDIR = "/ruby/1.9.1/gems/origami-1.2.4/lib" def initialize(file, options = {}, attachment = nil) @file = […]

回形针:无法附加XLS(但DOC工作)

我无法附加XLS文件,但DOC工作: 附件文件内容类型无效 附件文件无效 这是日志: Parameters: … “files”=>[#<ActionDispatch::Http::UploadedFile:0x0000000daf7730 @tempfile=#, @original_filename=”Chocolate_Store1.xls”, @content_type=”application/vnd.ms-excel”, @headers=”Content-Disposition: form-data; name=\”deal[files][]\”; filename=\”Chocolate_Store1.xls\”\r\nContent-Type: application/vnd.ms-excel\r\n”>], … Command :: file -b –mime “C:/Users/Chloe/AppData/Local/Temp/1f1fb4d71efc0bd245abd7b5b9aa661220170511-47156-1rqzd0q.xls” (1.0ms) ROLLBACK Rendering deals/edit.html.erb within layouts/application 当我测试类型时: >file -b –mime “C:/Users/Chloe/AppData/Local/Temp/1f1fb4d71efc0bd245abd7b5b9aa661220170511-47156-1rqzd0q.xls” application/vnd.ms-office; charset=binary 我在接受列表中有这种类型: class Attachment < ApplicationRecord has_attached_file :file validates_attachment_content_type :file, content_type: [ "application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.oasis.opendocument.text", "application/vnd.ms-excel", "application/vnd.ms-office", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.oasis.opendocument.spreadsheet" ] […]

Paperclip S3下载远程图像

我如何下载远程图像(http协议,url在image_remote_url属性中)并通过Paperclip将其保存为S3的附件? class Product :s3, :s3_credentials => “#{RAILS_ROOT}/config/s3.yml”, :path => “:class/:id/:style.:extension”, :bucket => “my_bucket”, :styles => { :icon => “32×32#”, } def fetch_image # how should this method look ? end end 方法“fetch_image”应该怎么样?

为Paperclip Imagemagikresize的模型提供变量字符串

我正在使用paperclip上传一些resize的图像。 其中一个我想要被裁剪为五种方式中的一种……无论如何,我通过手工改变它们来确定要裁剪的弦应该是什么样的,但是现在我需要制作那种动态以便回形针可以裁剪的根据用户的意愿…… 问题是我得到了 undefined local variable or method `params’ for # 我觉得很确定这是因为我试图按照我的意愿弯曲导轨。 无论如何,我认为我很清楚我正在尝试做什么……只需将crop_geometry_thumb变量提供给convert_options ……我应该在哪里实际使用我的模型才能找到它的逻辑? class Asset { :large => [‘700×700’, :jpg], :medium => [‘300×300>’, :jpg], :thumb => [“200×200>”, :jpg]}, :convert_options => {:thumb => crop_geometry_thumb}, ### supply a string from above… FAIL 🙁 :path => “:id/:style/:filename”, :storage => :s3, :s3_credentials => “#{RAILS_ROOT}/config/s3.yml”, :s3_permissions => :private, :url […]

Rails,Paperclip没有validation内容类型“application / octet-stream”?

我正在使用paperclip上传mime类型“application / octet-stream”的文件,但它们没有正确validation。 在控制器中,当我调用replay.save! ,我收到以下错误: Validation failed: r_file has contents that are not what they are reported to be, r_file is invalid, r_file content type is invalid 这是模型: class Replay < ApplicationRecord has_attached_file :r_file validates_attachment_content_type :r_file, content_type: { content_type: "application/octet-stream" } end 和重放控制器中的create方法: def create @replay = Replay.new(replay_params) if @replay.save # This never runs because […]

Image Paperclip :: Errors :: NotIdentifiedByImageMagickError #Windows

我已经厌倦了这个错误……我尝试了互联网上的一切(我发现到目前为止) gem gem ‘paperclip’, ‘~> 4.3’, ‘>= 4.3.6’ 配置/环境/ development.rb Paperclip.options[:command_path] = “/c/Program Files/ImageMagick-7.0.1-Q16/” Paperclip.options[:command_path] = ‘C:\Program Files (x86)\GnuWin32\bin’ ImageMagick / convert的路径 https://gyazo.com/2e8714546606b796b63f5b64663cab31 它安装的file.exe https://gyazo.com/5d0d3d5723c52e6cc812d72202ba4038 我的模特 has_attached_file :image, styles: { medium: “300×300>”} validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/