You don't need Paperclip or Carrierwave or even an ActiveRecord model to manage file uploads in Rails if all you need to do is read the file in and extract data from it.
The Catalog class (referenced in the UploadController#create
method) knows how to read a JSON file, translate and extract the data therein, and create or modify Book and Product records in the surrounding application.
By using the FileUtils.cp
class method, we move the uploaded file into a known location at a known filename, so the Catalog (PORO) can do its work. The tempfile created by Rack during the upload is harvested as normal by garbage collection, but the copy we made is deleted manually after the parsing process is completed.