Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 导轨、回形针不验证内容类型“;应用程序/八位字节流“;?_Ruby On Rails_Paperclip - Fatal编程技术网

Ruby on rails 导轨、回形针不验证内容类型“;应用程序/八位字节流“;?

Ruby on rails 导轨、回形针不验证内容类型“;应用程序/八位字节流“;?,ruby-on-rails,paperclip,Ruby On Rails,Paperclip,我正在使用回形针上传mime类型的文件“应用程序/八位字节流”,但它们没有正确验证 在控制器中,当我调用replay.save,我得到以下错误: 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 模型如下: class Replay < ApplicationRecord

我正在使用回形针上传mime类型的文件“应用程序/八位字节流”,但它们没有正确验证

在控制器中,当我调用
replay.save,我得到以下错误:

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
模型如下:

class Replay < ApplicationRecord
    has_attached_file :r_file
    validates_attachment_content_type :r_file, content_type: { content_type: "application/octet-stream" }
end
我检查了我试图上传的文件的mime类型,它的类型肯定是
“application/octet stream”
。回形针只是读取文件类型不正确吗

编辑:

以下是模式:

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

验证rails视频/图像中的所有格式

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'

曲别针不使用mime类型gem来计算它使用的文件类型
文件
检查它可能返回的文件与
应用程序/x-bittorrent
不同,但mime类型将其视为
八位字节流
文件类型是否会不同?我只是尝试使用
application/x-bittorrent
进行验证,但也不起作用。尝试允许所有
application/*
,然后检查回形针读取的文件是否不匹配即使操作系统看到相同的文件,类型验证也会失败
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'