Reputation: 61
I'm using paperclip to upload files of the mime-type "application/octet-stream", but they aren't validating properly.
In the controller, when I call replay.save!
, I get the following error:
Validation failed: r_file has contents that are not what they are reported to be, r_file is invalid, r_file content type is invalid
Here is the model:
class Replay < ApplicationRecord
has_attached_file :r_file
validates_attachment_content_type :r_file, content_type: { content_type: "application/octet-stream" }
end
and the create method in the replay controller:
def create
@replay = Replay.new(replay_params)
if @replay.save
# This never runs because it won't validate.
puts "REPLAY SAVED."
redirect_to @replay
else
puts "REPLAY NOT SAVED."
render 'new'
end
end
I checked the mime-type of the file I'm trying to upload, and it is definitely of type "application/octet-stream"
. Is Paperclip just reading the file type incorrectly?
EDIT:
Here is the schema:
ActiveRecord::Schema.define(version: 20161203161351) do
create_table "replays", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "map"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "r_file_file_name"
t.string "r_file_content_type"
t.integer "r_file_file_size"
t.datetime "r_file_updated_at"
end
end
Upvotes: 1
Views: 1812
Reputation: 180
Validate all formats in rails Video/Image
validates_attachment_content_type :media,
content_type: [
'image/jpg',
'image/jpeg',
'image/pjpeg',
'image/png',
'image/x-png',
'video/avi',
'video/mov',
'video/mp4',
'video/x-flv',
'video/3gpp',
'video/quicktime',
'video/x-msvideo',
'video/x-ms-wmv',
'flv-application/octet-stream',
'application/octet-stream',
'video/x-flv',
'video/mpeg',
'video/mpeg4',
'video/x-la-asf',
'video/x-ms-asf'
],
:message => 'file type is not allowed'
Upvotes: 1