【发布时间】:2011-07-26 19:07:59
【问题描述】:
我有一个应用程序必须几乎接受所有文件类型,除了那些已知的恶意文件(即 exe、dll、bat 等)。我正在使用回形针,想知道是否有办法做到这一点。在 github 上提交 https://github.com/thoughtbot/paperclip/commit/020625921adae884534608d76c11f65692e4bbec 之后,看起来有可能。但我不确定。
更新:我找不到回形针的处理方式,但我确实添加了这个自定义验证:
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
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 paperclip attachment