【发布时间】:2012-11-26 01:37:10
【问题描述】:
rails 3 中的回形针有问题。当我上传文件时,我的处理器抛出错误,因为 imagemagick get 命令:
“复合-重力南 /home/xxx/xxx/public/images/watermark.png /tmp/a s20121207-5819-1dq7y81.jpg /tmp/a s20121207-5819-1dq7y8120121207-5819-1juqw7a”
复合:无法打开图像`/tmp/a':
处理器:
def make
dst = Tempfile.new([@basename, @format].compact.join("."))
dst.binmode
if @watermark_path
command = "composite"
params = "-gravity #{@position} #{@watermark_path} #{fromfile} "
params += tofile(dst)
begin
p " >>>>>>>>>>>>>>>>> #{command} #{params}"
success = Paperclip.run(command, params)
rescue PaperclipCommandLineError
success = false
end
unless success
raise PaperclipError, "There was an error processing the watermark for #{@basename}" if @whiny
end
return dst
else
return @file
end
end
def fromfile
File.expand_path(@file.path)
end
def tofile(destination)
File.expand_path(destination.path)
end
它仅在文件名包含空格或其他非 alfanum 字符时发生。 /tmp/a 应该是 /tmp/a b.jpg。
我尝试了http://www.davesouth.org/stories/make-url-friendly-filenames-in-paperclip-attachments 等等,但处理器中的文件名仍然错误
有什么想法吗?或适用于这个问题的处理器? :(
【问题讨论】:
-
你应该从文件名中删除空格...
-
我已经这样做了,但它不起作用我认为回形针会在删除空格之前创建 tmp 文件
-
但是你自己创建临时文件?? dst = Tempfile.new([@basename, @format].compact.join("."))
-
不,这个文件传入构造函数:def 初始化文件,选项 = {},附件 = nil super
-
这个问题好运吗?我有完全相同的问题。我正在查看源代码,但我只是找不到如何从@file.path 中删除非法字符。我只是在 photo_file_name 上有一个 validate_format_of 来安定下来,这并不是这个问题的直接解决方案。
标签: ruby ruby-on-rails-3 paperclip