Using :db_file as storage type in attachment_fu

I've successfully been using attachment_fu with the :file_system
storage type, but am looking to switch over to using MySQL to store
the images instead. First off, the reason I'm thinking of doing this
is to hold all images centrally. Thinking being that it will help
scalability, by avoiding filesystem related issues with multiple
machines. Yeah, maybe I'm looking too far ahead ?.

Howandever, there's a one liner in the attachment_fu README that says

"When serving files from database storage, doing more than simply
downloading the file is beyond the scope of this document."

OK, I respect that, but ... I'm also now lost. Problem being that the
handy public_filename() method only exists for file and S3 storage
types. How does one take the binary data directly from the DB and
display it in a view ?. I spent a little time peeking at the
file_column plugin, thinking it probably had code to do this by
default, but ... it didn't jump right out at me ... I'm more a jack of
all trades rather than a master of RoR :0((.

This is surely easy enough ? ... i.e taking image data from a database
field ( a BLOB field in MySQL) and displaying it in an RHTML view.

Would very much appreciate a pointer on how its done, or a link to
some sample code that does this.

Thanks in Advance,
Attila

You don't just store blobs in HTML, you'll need to write some custom
controller actions that read from the database and stream the blob
data out. Look at the send_data method in ActionController.

Problem is that Mongrel buffers everything from rails, so this will
cause memory leaks if you're serving large files.

Hi Rick,

Thanks for both the plugin and the comment. I very much appreciate
all the many plugin contributors to the land of RoR. I've been
teaching myself Ruby and Rails for the last 9 months, and would not
have been able to get anywhere near as productive without help from
you folks.

As for my problem ... your hint about memory leak issues brings some
caution to my thinking, and am now thinking I'm better off for the
time being deferring the problem until I actually need to solve it ...
re: if and when I need to scale to multiple machines ;0).

I will have a dabble though, just to see what might be involved.

Thanks again,
Attila

This won't help your scalability. MySQL doesn't handle blob fields
very well, and having to perform database queries to show assets is
going to slow things down over time. There are considerably faster and
more scalable methods for delivering assets from the filesystem. If
you want to centralize the location of the files, you have many
options, such as a separate assets server, NFS, SAN, or Amazon S3. Of
course, I wouldn't even bother with this until you really need it,
because it's not hard to switch (move the files to a shared partition,
or sftp them over, then change a few attachment_fu settings and URLs)

Hi Jeff,

OK ... that's the sorta info I was looking for ... i.e. whether MySQL
was a good choice or not for images. I know a fair amount about the
legacy centralised file storage options, I've a Telco on Sun Solaris
background, but I've seen quite a few references to Amazons S3. I've
not really looked into it, but I will.

Thanks,
Attila

Did any of You find attachment_fu working with rails 2 version?

mariek wrote:

Did any of You find attachment_fu working with rails 2 version?

I have it working just fine, except it won't save attachments to the
databank. But after reading this thread, I guess I don't care so much.
But I'm sure someone somewhere does.