Skip to content
Snippets Groups Projects
Commit d020b5b6 authored by Kapil Patel's avatar Kapil Patel Committed by Anusha Ranganathan
Browse files

Add validation for uploded file

parent bbee3ce4
Branches
Tags
1 merge request!225Add validation for uploded file
......@@ -15,6 +15,7 @@ module Hyrax
belongs_to :user, class_name: '::User'
before_create :set_characterization_data
validate :uploaded_file_name
##
# Associate a {FileSet} with this uploaded file.
#
......@@ -44,5 +45,14 @@ module Hyrax
self.characterization_data[:file_size] = file.size
self.characterization_data[:original_checksum] = Digest::SHA1.file(file.path).to_s
end
def uploaded_file_name
parsed_file = YAML.load_file(Rails.root.join('config', 'restricted_files.yml'))
file_name = file.file.original_filename
if parsed_file['restricted_file_names'].include?(file_name.gsub(/[\s_\-]/, '').downcase) || file_name.start_with?('.')
errors.add(:base, "This file name is restricted.")
end
end
end
end
\ No newline at end of file
restricted_file_names:
- metadata.json
- meta.json
- .DS_Store
- desktop.ini
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment