paperclip-validation

Rails 4, Paperclip 4.2.1 give error with binary file upload

左心房为你撑大大i 提交于 2020-01-03 19:32:27
问题 I have following setup with rails 4 and paperclip 4.2.1 class Post< ActiveRecord::Base has_attached_file :key allowed_content_type = ['text/plain', 'text/rtf', 'text/richtext', 'application/txt', 'application/octet-stream'] validates_attachment_content_type :key, :content_type => allowed_content_type, :message=> "Only #{allowed_content_type} is allowed" I have this in my application.rb <body data-controller="<%= controller.controller_path %>" data-action="<%= controller.action_name %>" data

Rails 4, Paperclip 4.2.1 give error with binary file upload

自闭症网瘾萝莉.ら 提交于 2020-01-03 19:32:10
问题 I have following setup with rails 4 and paperclip 4.2.1 class Post< ActiveRecord::Base has_attached_file :key allowed_content_type = ['text/plain', 'text/rtf', 'text/richtext', 'application/txt', 'application/octet-stream'] validates_attachment_content_type :key, :content_type => allowed_content_type, :message=> "Only #{allowed_content_type} is allowed" I have this in my application.rb <body data-controller="<%= controller.controller_path %>" data-action="<%= controller.action_name %>" data

no validates_attachment_file_name when upgrading to Paperclip 4.1 from 3.5

女生的网名这么多〃 提交于 2019-12-22 10:14:27
问题 We have code that looks like run of the mill paper clip: has_merchants_attached_file :pdf, storage: :s3, s3_credentials: Mbc::DataStore.s3_credentials, s3_permissions: :private, path: ":identifier_template.pdf", bucket: Mbc::DataStore.forms_and_templates_bucket_name validates_attachment_file_name :pdf, :matches => [/pdf\Z/] Which generates an error: undefined method `validates_attachment_file_name' for #<Class:0x007fba67d25fe0> Interestingly enough, when we down grade back to 3.5, we

Validate extension in Paperclip - Ruby on Rails

隐身守侯 提交于 2019-12-18 21:19:16
问题 I've found that Paperclip can validate file content type, i.e. image/jpeg, but I want to specifically validate the extension. This is because I'm working with an obscure extension that won't get a consistent content type. Anyone know if this is doable, or a good way to do this? 回答1: Guess, there is no need to validate it with paperclip's method. You can rather use something like: has_attached_file :attachment validates_format_of :attachment_file_name, :with => %r{\.(docx|doc|pdf)$}i Edit:

Paperclip- validate pdfs with content_type='application/octet-stream'

耗尽温柔 提交于 2019-12-18 11:18:22
问题 I was using paperclip for file upload. with validations as below: validates_attachment_content_type :upload, :content_type=>['application/pdf'], :if => Proc.new { |module_file| !module_file.upload_file_name.blank? }, :message => "must be in '.pdf' format" But, my client complained today that he is not able to upload pdf . After investigating I come to know from request headers is that the file being submitted had content_type=application/octet-stream . Allowing application/octet-stream will

Paperclip- validate pdfs with content_type='application/octet-stream'

社会主义新天地 提交于 2019-12-18 11:17:59
问题 I was using paperclip for file upload. with validations as below: validates_attachment_content_type :upload, :content_type=>['application/pdf'], :if => Proc.new { |module_file| !module_file.upload_file_name.blank? }, :message => "must be in '.pdf' format" But, my client complained today that he is not able to upload pdf . After investigating I come to know from request headers is that the file being submitted had content_type=application/octet-stream . Allowing application/octet-stream will

Rails: prevent submitting form if field is blank

点点圈 提交于 2019-12-12 03:49:08
问题 I am creating product page, where user can upload more than one photo of product. To create and edit product, i am rendering a form file. For uploading photos, i have used nested_fields for photos in the form of the product. Here is how photo code in the form looks like: <%= f.fields_for :photos do |photo| %> <%= image_tag photo.object.avatar.url(:thumb), unless f.object.new_record? or photo.object.new_record? %> <%= photo.file_field :avatar, :style => "none" %> <%= photo.link_to_remove

Paperclip: Cannot attach XLS (But DOC works)

元气小坏坏 提交于 2019-12-11 05:57:40
问题 I cannot attach a XLS file, but DOC works: Attachments file content type is invalid Attachments file is invalid Here is the log: Parameters: ... "files"=>[#<ActionDispatch::Http::UploadedFile:0x0000000daf7730 @tempfile=#<Tempfile:C:/Users/Chloe/AppData/Local/Temp/RackMultipart20170511-47156-ym774u.xls>, @original_filename="Chocolate_Store1.xls", @content_type="application/vnd.ms-excel", @headers="Content-Disposition: form-data; name=\"deal[files][]\"; filename=\"Chocolate_Store1.xls\"\r

Paperclip validation issue on production

可紊 提交于 2019-12-08 08:48:50
问题 I have a Problem when I deploy my application on google cloud I get this error has contents that are not what they are reported to be Locally it works fine! I already tried to using the command_path. So I really don't know what I have to do next... This is my model has_mongoid_attached_file :image, :styles => { :large => "380x380!" , :medium => "240x240", :small => "120x120!" }, :storage => :fog, :fog_public => true, :fog_directory => 'XXXX', :path => "images/:id/:style/:basename.:extension",

validates_attachment for optional field

早过忘川 提交于 2019-12-08 07:50:43
问题 I have an uload field which is optional, it can be left empty. But when it is is used, I want to validate the size and content of the attachment. So I use this validation in the model: validates_attachment :attachment, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }, size: { in: 0..500.kilobytes } This works when there is an attachment, but fails when it is left empty. How can I make sure it only validates when there is an attached file? The solutions mentioned here