Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

tell carrierwave to use move instead of copy during uploads #149

Merged
merged 1 commit into from
Jan 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/uploaders/file_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ class FileUploader < CarrierWave::Uploader::Base
before :store, :remember_cache_id
after :store, :delete_tmp_dir

##
# By default, CarrierWave copies an uploaded file twice, first copying the file into the cache, then copying the file into the store.
# For large files, this can be prohibitively time consuming.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for doing this? Are we seeing this as an issue? Are these directories on the same file system?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are occasional issues where a very big file fails to upload correctly and/or where the tmp space fills up. Thought this could potentially help those scenarios by avoiding a seemingly unnecessary big file copy, but I don't have data to back that up.

# You may change this behavior by overriding either or both of the move_to_cache and move_to_store methods and set values to true.
def move_to_cache
true
end

def move_to_store
true
end
##

# store! nil's the cache_id after it finishes so we need to remember it for deletion
def remember_cache_id(new_file)
@cache_id_was = cache_id
Expand Down