I'm indexing a music library, and trying to use Paperclip to manage the cover art associated with each album, as well as generating some various sized thumbnails, which seems like an ideal use for Paperclip.
I'm extracting the album art using the mp3info library, which returns a "blob" of the image data in the form of a string.
I have an Album class which descends from ActiveRecord::Base, and I've done the standard:
has_attached_file :cover_art, :styles => { :medium => "300x300>", :thumb => "100x100>" }
...referenced in the examples.
I'm at a bit of a loss as to how to try to attach this blob with Paperclip. I'd like to avoid writing the blob out to a tempfile if possible. I've tried various approaches using a StringIO, such as:
update_attributes :cover_art => StringIO.new(blob)
cover_art.assign StringIO.new(blob)
self.cover_art = StringIO.new(blob)
as far as I can tell, none of these seem to be working. I'm also at a loss as to how to test if the fine actually got attached. The RDoc at:
http://github.com/thoughtbot/paperclip/blob/master/README.rdocDescribes the following method:
file?
Returns true if a file has been assigned.
However when I try to use this in my tests to verify the file was attached successfully:
undefined method `file?' for #<Paperclip::Attachment:0x2522f04>
This is with Paperclip 2.1.2.
Looking at the source I see file? checks original_filename is not nil. Trying that out with all the above approaches, and something like:
cover_art.assign StringIO.new(blob)
cover_art.save
The cover_art.save call returns true, and yet when I check if original_filename is nil:
expected nil? to return false, got true
I'm confused... help?