I want to configure an upload path for Carrier wave Direct,which I am using to upload files directly to Amazon s3.In app/uploaders/myuploader.rb ,I have,
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
I want to modify this so that,the path looks like,
“uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{User.name}”.
so it will be some thing like,
“uploads/Users/avatar/michael_jordan/..”
Where User is the model in which the uploader is mounted.
I have gone through the source code of Carrier wave Gem in github(https://github.com/dwilkie/carrierwave_direct) and I couldn’t figure out how to pass a value from the active model object to the uploader to create the upload path(key for amazon s3). Is there a way to do this?
Thanks!
Dragon
Ok.after one month I was forced to work on the same problem and this time I nailed it.Posting my solution here so that it may help others having the same problem,
1)Override store_dir such that it returns an empty string,
2)got to your controller and assign your preferred key to the “key” attribute of your uploader object like,
here player is the model object,avatar is the property on which the uploader is mounted and the key will be set as playername/filename.
Which was what I was looking for 🙂