class Wco::Photo

def decode_base64_image

def decode_base64_image
  if image_data && content_type && original_filename
    decoded_data = Base64.decode64(image_data)
    data = StringIO.new(decoded_data)
    data.class_eval do
      attr_accessor :content_type, :original_filename
    end
    data.content_type = content_type
    data.original_filename = File.basename(original_filename)
    self.photo = data
  end
end

def export_fields

def export_fields
  %w|
    gallery_id
    name descr weight
    photo_file_name photo_content_type photo_file_size photo_updated_at photo_fingerprint
  |
end

def name

def name
  if !self[:name]
    update_attribute(:name, self.photo.to_s.split('/').last.split('?').first)
  end
  self[:name]
end