我有一個應用程序,必須接受幾乎每個文件類型,除了那些已知是很爛(即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,它仍然上傳大圖像,但不生成縮略圖。 –