我有一个应用程序,必须接受几乎每个文件类型,除了那些已知是很烂(即exe,dll,蝙蝠等)。我正在使用回形针,并想知道是否有办法做到这一点。在github上提交之后,https://github.com/thoughtbot/paperclip/commit/020625921adae884534608d76c11f65692e4bbec看起来好像有可能。但我不确定。有没有办法在Paperclip中黑名单扩展?
更新:我找不到做事情的回形针的方式,但是我没有添加这个自定义的验证:
def extension_not_blacklisted?
#An attempt to make a blacklist command when saving...
forbiden_types = Array.new()
forbiden_types << "jpg" << "exe" <<"dll"
path_array = attachment.to_s.split(".")
extension = path_array.pop
extension_with_extras = extension.to_s.split("?")
extension = extension_with_extras[0]
forbiden_types.each do |f|
if f == extension
errors.add(:attachment,'FORBIDEN FILE EXTENSION: ' + extension)
end
end
的before_post_process似乎只适用于制作缩略图的形象,因为我返回false,它仍然上传大图像,但不生成缩略图。 –