In my rails 4 app, I'm using carrierwave to upload files to google cloud storage. I'm able to successfully upload image files, but pdfs are not working. It shows following error:
You are not allowed to upload "pdf" files, allowed types: jpg, jpeg, gif, png
Here is my uploader:-
# 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
I don't know what's wrong with this code.
And here's the attachment model
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: When testing on local machine it works but not on heroku. On development env it works without issue and I can check file uploaded to google storage. But on heroku it displays error "You are not allowed to upload "pdf" files, allowed types: jpg, jpeg, gif, png"
Thanks in advance!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire