Posted over 5 years ago. Visible to the public. Linked content.

Caution: Carrierwave has your file three times (temporarily)

When storing a file with Carrierwave, it is always cached prior to actually storing it (to support form roundtrips Archive ).

Carrierwave by default 1) copies the file to the cache and then 2) copies it again to its final destination (deleting the cached file immediately after storing). This means there are 3 (three) instances of a file on the disk at some point in time, and still 2 instances after Carrierwave is done if you do not remove the original file manually.

Usually this is not an issue, because a file upload from a browser will immediately write to the cache, and most files are of a size that is still ok when tripled. However, this can become an issue with large files, regarding both time and disk usage.

Suggested solution for large files

You can easily configure Carrierwave to move the files instead of copying them. Simply define two methods in your uploader class:

def move_to_cache true end def move_to_store true end


Your development team has a full backlog of feature requests, chores and refactoring coupled with deadlines? We are familiar with that. With our "DevOps as a Service" offering, we support developer teams with infrastructure and operations expertise.

Owner of this card:

Dominik Schöler
Last edit:
almost 5 years ago
by Dominik Schöler
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more