CarrierWave and Fog, S3 bucket and store_dir configuration
Date : March 29 2020, 07:55 AM
|
Carrierwave: file hash and model id in filename/store_dir
Date : March 29 2020, 07:55 AM
This might help you Including the id in the filename on create may not be possible, since the filename is stored in the database but the id isn't available yet. An (admittedly rather extreme) workaround would be to use a temporary value on create, and then after_commit on: :create, move the file and change the name in the database. It may be possible to optimize this with an after_create, but I'll leave that up to you. ( This is where carrierwave actually uploads the file.)
|
Carrierwave is appending the store_dir when referencing filename
Date : March 29 2020, 07:55 AM
To fix the issue you can do I finally figured this out after inspecting the methods available to my object. To get the raw file name, I used the following pattern:
|
Carrierwave on Rails with ActiveDirectory adds tmp folder in store_dir
Date : March 29 2020, 07:55 AM
should help you out You can instruct Carrierwave to move the file to your storage directory, rather than copy it by overriding the move_to_cache and move_to_store methods in your uploader. class MyUploader < CarrierWave::Uploader::Base
def move_to_cache
true
end
def move_to_store
true
end
end
|
CarrierWave File Upload store_dir in parent association
Date : March 29 2020, 07:55 AM
help you fix your problem As model is the ActiveRecord instance that mounts the uploader you should be able to use the ActiveRecord associations. Since you state that Document belongs_to a Request (and I assume that Document is the ActiveRecord that mounts the uploader) you can get the Request's id with model.request_id (or model.request.id). def store_dir
"uploads/#{model.request_id}/#{model.id}"
end
|