Attachment_fu with S3: custom path?

Hi,

I recently saw the light and have moved my storage from the server to
the wonderful Amazon S3 service. I am also using the equally great
attachment_fu plugin.

I would like to store the uploaded files in a path such as:

/photos/[user_id]/[photo.id].jpg

Instead of the default:

/photos/[photo.id]/[filename]

Has anyone customised the path like this? Any tips or pointers?

Thanks,
GiantCranes

On 3/24/07, Giant C. [email protected] wrote:

Instead of the default:

/photos/[photo.id]/[filename]

Has anyone customised the path like this? Any tips or pointers?

Thanks,
GiantCranes

You can just redefine the full_filename method to fit your custom needs.


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com

Rick O. wrote:

You can just redefine the full_filename method to fit your custom needs.

Thanks for point out that Rick, I have tried doing the following (Photo
belongs to Vehicle belongs to Seller):

def full_filename
return “photos/#{self.vehicle.seller.id}/#{self.vehicle.id}/#{id}” +
File.extname(filename)
end

This works on photos that have already been saved, but throws an
exception when uploading new photos:

‘You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.seller’

This is puzzling to me, as the photo does have a Vehicle ion the
controller:

def upload_vehicle_photo
vehicle = Vehicle.find(params[:id])
@photo = Photo.new(params[:photo])
vehicle.photos << @photo

if @photo.save
  flash[:information] = 'The photo was successfully uploaded.'
end

redirect_to :action => 'edit_vehicle_photos', :id => params[:id]

end

Am I doing anything obviously wrong here?

Thanks for any insight and for providing this great plugin.

GiantCranes

I posted a short guide on how to do this at
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/6a4aa492722da26a?hl=en

Eric

Eric N. wrote:

I posted a short guide on how to do this at
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/6a4aa492722da26a?hl=en

Eric

Thanks Eric, that look like exactly what I need.