I use Carrierwave, s3 and fog to download the video. I added the file file_size_validator so that the video does not exceed 5 MB.
My understanding of how Carrierwave works (please let me know if this is incorrect). Carrierwave saves a copy of the file to the tmp file folder, and then checks on it, so if it passes, the file is uploaded to S3, and the code below deletes the tmp file from the local file system:
video_uploader.rb
before :store, :remember_cache_id after :store, :delete_tmp_dir def cache_dir Rails.root.join('public/uploads/tmp/videos') end
If the file does not pass the verification, the before_store and after_store calls are not called, and the tmp file remains in the tmp folder and is not deleted.

So we have to deal with deleting these files (again, please let me know if there is a general way to do this). I created a cron rake task that removes screenshots associated with videos that work very well, and then used a similar format to delete these temporary files and folders. When I try to start a task, I get the following errors:
video.rake
task :delete_tmp_files do FileUtils.rm Dir.glob("#{Rails.root}/public/uploads/tmp/screenshots/*") end task :carrierwave_tmp do CarrierWave.clean_cached_files! end task :delete_unsaved_videos do FileUtils.rm Dir.glob("#{Rails.root}/public/uploads/tmp/videos/*") end rake delete_unsaved_videos rake aborted! Operation not permitted - /user/me/projects/teebox_network/public/uploads/tmp/videos/20130421-1853-8808-1646
running rake with sudo (for debugging only) causes this.
sudo bundle exec rake delete_unsaved_videos Could not find rake-10.0.4 in any of the sources Run `bundle install` to install missing gems.
A running package installation did not achieve anything.
Does anyone know why this is happening? Is it a permission error when trying to delete these folders? Is there a better way to deal with tmp files that fail validation?