在我的rails 4应用程序中,我使用carrierwave将文件上传到谷歌 Cloud 存储 . 我能够成功上传图像文件,但pdfs不能正常工作 . 它显示以下错误:
You are not allowed to upload "pdf" files, allowed types: jpg, jpeg, gif, png
这是我的上传者: -
# encoding: utf-8
require 'carrierwave/processing/mime_types'
class AttachmentUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include CarrierWave::MimeTypes
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
process :set_content_type
def extension_white_list
%w(jpg jpeg gif png pdf)
end
end
我不知道这段代码有什么问题 .
这是附件模型
class Attachment < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader
# Associations
belongs_to :attached_item, polymorphic: true
# Validations
validates_presence_of :attachment
validates_integrity_of :attachment
# Callbacks
before_save :update_attachment_attributes
# Delegate
delegate :url, :size, :path, to: :attachment
# Virtual attributes
alias_attribute :filename, :original_filename
private
def update_attachment_attributes
if attachment.present? && attachment_changed?
self.original_filename = attachment.file.original_filename
self.content_type = attachment.file.content_type
end
end
end
Update :在本地计算机上进行测试时,它可以正常运行,但不能在heroku上运行 . 在开发环境中它没有问题,我可以检查上传到谷歌存储的文件 . 但在heroku上显示错误"You are not allowed to upload " pdf " files, allowed types: jpg, jpeg, gif, png"
Update :我的应用程序ImageUploader还有另一个上传器 . 当我将extension_white_list设置为包含pdf时,它也使attachment_uploader工作 . 怎么样?我需要在所有上传者中使用相同的extension_white_list吗?
提前致谢!