I recently updated to Paperclip 4 (4.1.1 to be specific) where it is necessary to validate files with validates_attachment
. I tried it 3 ways, as the GitHub docs suggest:
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
and the 2 ways suggested in this thread.
All the cases give me an ActiveRecord::RecordInvalid
exception saying the image's content type is invalid.
I create the image using this line of code in a Grape API:
image = ActionDispatch::Http::UploadedFile.new(params[:data])
The data it receives comes from Android using Apache HttpClient
's MultipartEntityBuilder
It prints the command it runs to check the mime type which is like file -b --mime-type '/path/to/file
but when I run it, it gives me image/jpeg
The class only has 2 other lines:
has_attached_file :image
attr_accessible :image
And ideas why does it constantly fail?
I went into the same issue than you (even tried the other ways the thread suggests), and Rachel is right about the version. Paperclip 4 has some issue with spoofing. Changing it to 3.5 solved my problem.
Btw, if you still want to make it work, it seems to be the issue discussed here ( with a workaround given )