Using the (very nifty) attachment_fu plugin. It would be very
convenient if I could batch-load a lot of my model objects that have
attachments, instead of having to load them interactively via a web
page.
Experimented with calling uploaded_data= directly, but didn't work,
and I'm not sure that's the right route. Any suggestions?
Not sure if this is what you're after or not. We have some scenarios
in which we create files (reports) on the webserver in response to a
user request and then save them on the server using an attachment_fu-
based model. It's similar in that we're creating the model with a
file but avoiding the interactive part.
It was as simple as setting <model>.temp_path. Note that this works
for us because we're storing objects in the file system rather than
the DB/S3. temp_path is mixed in for file system storage; not sure
about the others.
Actually, having followed a suggestion in the comments to that blog
entry, there's even an easier way (below, ImageMetadata is my class
that has_attachment):
script/console
Mime::Type.register "image/gif", :gif
=> ["gif"]
t = ActionController::TestUploadedFile.new('db/seed-data//tile-samples/bippy2.gif', Mime::GIF)