title: Manually upload and save files in Carrierwave
body: <p>I have a directory of existing files which I need to migrate into my rails app as part of a legacy migration. Essentially I need to upload these files manually and save a new record for them in the database. I haven't quite found the proper way to do this. Currently I have the following in a rake task:</p>
  
  <pre><code>@attachments.each do |attachment|
    begin
      new_attachment = Attachment.new
  
      @attachment_file_path = "/home/username/Attachments/" + attachment.Filename
      file = File.open(@attachment_file_path)
      new_attachment[:file] = new_attachment.file.store!(file)
  
      # Map old record fields to new
      new_attachment.attributes = {
          :project_id =&gt; attachment.ProjectID,
          :name =&gt; attachment.Description,
          :user_id =&gt; attachment.UserId,
          :created_at =&gt; attachment.CreatedDate,
          :updated_at =&gt; attachment.LastModifiedDate
      }
  
      new_attachment.save!
  
      puts "Attachment added successfully "
  
    rescue =&gt; error
      puts "Error migrating Attachment: #{error}"
    end
  end
  </code></pre>
  
  <p><strong>attachment.rb</strong></p>
  
  <pre><code>class Attachment &lt; ActiveRecord::Base
       mount_uploader :file, FileUploader
  end
  </code></pre>
  
  <p><strong>uploader:</strong></p>
  
  <pre><code>class FileUploader &lt; CarrierWave::Uploader::Base
  
    include CarrierWave::RMagick
    include CarrierWave::MimeTypes
  
    process :set_content_type
    storage :fog
  
    def store_dir
      "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
    end
  
    def extension_white_list
      %w(jpg jpeg gif png pdf doc docx txt)
    end
  
    version :thumb do
      process resize_to_fit: [152, nil]
    end
  
    def default_url
        ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
    end
  
    protected
      def image?(new_file)
        if new_file.content_type == nil
          return false
        else
          new_file.content_type.include? 'image'
        end
      end
  
  
  end
  </code></pre>
  
  <p>This does not work currently. The file never gets uploaded, and occasionally I get the following error:</p>
  
  <pre><code>Failed to manipulate with rmagick, maybe it is not an image? Original Error: no decode delegate for this image format
  </code></pre>
  
  <p>In this instance, the file is a '.doc' file.</p>
  
  <p>What is the correct way to open a local file and upload it manually via Carrierwave?</p>
  
  <p>Any help is appreciated.</p>