Every repository with this icon (
Every repository with this icon (
Home
This is a forked repository. Have a look at technoweenie’s attachment_fu wiki for more information.
—Modified to allow DEFERRED saving to S3. Why? Because saves to S3 can take some time for large files, and people using your web site don’t want to wait. If yourmodelitem.s3_defer_save is called (hopefully before you save the item), the item WILL NOT be uploaded to S3 on the yourmodelitem.save call. yourmodelitem.is_on_s3? will return false. What you might like to do is set the has_attachment configuration parameter :s3_after_deferred_save like this: :s3_after_deferred_save=>:queue_to_s3; you probably want a field in your model like yourmodelitem.on_disk_location (a string), that will be set to yourmodelitem.temp_path (say, after an upload, before the item save)...
then set up a message broker, activemessaging, etc. and def queue_to_s3 like so: def queue_to_s3 publish :queue_to_s3, {:id=>self.id}.to_json end
Your queue_to_s3 message processor will lift the id of the object out of the message, then just do yourmodelitem.temp_path = yourmodelitem.on_disk_location # DON’T call yourmodelitem.s3_defer_save yourmodelitem.save! # yourmodelitem.is_on_s3? will return TRUE after the object is moved to S3.
While yourmodelitem.is_on_s3 returns FALSE, you might want to serve it to your customers from yourmodelitem.on_disk_location
this version of the S3_backend requires the following new fields: storage_spec : integer, default=>0 the :s3_after_deferred_save parameter COULD be specified like a callback, ala :after_attachment, however it’s really S3 backend specific. I will have to think about that a bit more.





