copying an image from one mount (+model) to another

Showing 1-3 of 3 messages
copying an image from one mount (+model) to another Joey 12/7/11 3:10 PM
Hi all,

I have a need to occasionally populate the image(s) stored on one
model's uploader from another. E.g.,

class Artwork
  mount_uploader :image, ArtworkUploader
end

class Artist
  mount_uploader :image, ArtistUploader

  # copy an artwork image into the artist and perform necessary
processing
  def replace_image_from(artwork)
    artwork.image.cache_stored_file! unless artwork.image.cached?
    self.image_cache = artwork.image_cache
    self.store_image!
  end
end

This almost worked, but our uploaders increment a version number that
goes into the store_path, and it turns out that calling
artwork.image.cache_stored_file! increments the version number on the
artwork, which actually hasn't changed. Is there a simpler way to read
the original file from one mount point into another?

Thanks,
Joey

Re: copying an image from one mount (+model) to another Joey 12/10/11 6:03 PM
For those interested, this somewhat simpler approach has the desired
effect:

class Artist
  mount_uploader :image, ArtistUploader
  def replace_image_from(artwork)    self.image = artwork.image.file 
  self.save!  endend
Re: copying an image from one mount (+model) to another equivalent8 12/12/14 1:26 AM
Don't know if this is still relevant but you can use my gem ( or just copy code from it, it's just one file)  https://github.com/equivalent/copy_carrierwave_file 

with it you can do something like: 

original_resource = Artist.last
new_resource      = Artwork.new

CopyCarrierwaveFile::CopyFileService.new(original_resource, new_resource, :image).set_file
  # :avatar represents mount point (field)

new_resource.save