<commit_before>Technoweenie::AttachmentFu::InstanceMethods.module_eval do
  require 'rack'
  
  # Overriding this method to allow content_type to be detected when
  # swfupload submits images with content_type set to 'application/octet-stream'
  alias_method :original_uploaded_data=, :uploaded_data=
  def uploaded_data=(file_data)
    if self.is_a?(Attachment)
      return nil if file_data.nil? || (file_data.respond_to?(:size) && file_data.size == 0)
      # glean information from the file handle
      self.content_type = detect_mimetype(file_data) rescue 'unknown/unknown'
      self.filename     = file_data.original_filename if respond_to?(:filename) && file_data.respond_to?(:original_filename)
      file_from_path = true
      unless file_data.respond_to?(:path)
        file_data.rewind
        self.temp_data = file_data.read
        file_from_path = false
      else
        self.temp_paths.unshift file_data
      end
      # If we're overwriting an existing file, we need to take serious
      # precautions, since other Attachment records could be using this file.
      # We first remove any root references for this file, and then we generate
      # a new unique filename for this file so anybody children of this attachment
      # will still be able to get at the original.
      if !self.new_record?
        self.root_attachment = nil
        self.root_attachment_id = nil
        self.scribd_mime_type_id = nil
        self.scribd_user = nil
        self.submitted_to_scribd_at = nil<commit_msg>fix local storage with StringIO attachment uploads<commit_after>Technoweenie::AttachmentFu::InstanceMethods.module_eval do
  require 'rack'
  
  # Overriding this method to allow content_type to be detected when
  # swfupload submits images with content_type set to 'application/octet-stream'
  alias_method :original_uploaded_data=, :uploaded_data=
  def uploaded_data=(file_data)
    if self.is_a?(Attachment)
      return nil if file_data.nil? || (file_data.respond_to?(:size) && file_data.size == 0)
      # glean information from the file handle
      self.content_type = detect_mimetype(file_data) rescue 'unknown/unknown'
      self.filename     = file_data.original_filename if respond_to?(:filename) && file_data.respond_to?(:original_filename)
      file_from_path = true
      unless file_data.respond_to?(:path) && file_data.path.present?
        file_data.rewind
        self.temp_data = file_data.read
        file_from_path = false
      else
        self.temp_paths.unshift file_data
      end
      # If we're overwriting an existing file, we need to take serious
      # precautions, since other Attachment records could be using this file.
      # We first remove any root references for this file, and then we generate
      # a new unique filename for this file so anybody children of this attachment
      # will still be able to get at the original.
      if !self.new_record?
        self.root_attachment = nil
        self.root_attachment_id = nil
        self.scribd_mime_type_id = nil
        self.scribd_user = nil
        self.submitted_to_scribd_at = nil
{'fraction_non_alphanumeric': 0.06797680412371133, 'fraction_numerical': 0.0006443298969072165, 'mean_word_length': 3.2946058091286305, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4806158', 'n_tokens_mistral': 908, 'n_tokens_neox': 895, 'n_words': 270}