diff --git a/app/controllers/isolates_controller.rb b/app/controllers/isolates_controller.rb index fb5ab792..5dd87d2a 100644 --- a/app/controllers/isolates_controller.rb +++ b/app/controllers/isolates_controller.rb @@ -59,7 +59,11 @@ def import file = params[:file] if file - IsolateImporter.perform_async(params[:file], current_user.default_project_id) + file_name = file.original_filename + path = File.join("tmp", file_name) + File.open(path, "wb") { |f| f.write(file.read) } + + IsolateImporter.perform_async(path, current_user.default_project_id) redirect_to isolates_path, notice: "Isolate and specimen data will be imported in the background." else diff --git a/app/models/isolate.rb b/app/models/isolate.rb index 144ef33f..d706e37e 100644 --- a/app/models/isolate.rb +++ b/app/models/isolate.rb @@ -49,8 +49,8 @@ class Isolate < ApplicationRecord scope :recent, -> { where('isolates.updated_at > ?', 1.hours.ago) } scope :no_controls, -> { where(negative_control: false) } - def self.import(file, project_id) - spreadsheet = Isolate.open_spreadsheet(file) + def self.import(file_path, project_id) + spreadsheet = Roo::CSV.new(file_path) header = spreadsheet.row(1) (2..spreadsheet.last_row).each do |i| diff --git a/app/workers/isolate_import.rb b/app/workers/isolate_importer.rb similarity index 92% rename from app/workers/isolate_import.rb rename to app/workers/isolate_importer.rb index b4ba0dc5..9f86de40 100644 --- a/app/workers/isolate_import.rb +++ b/app/workers/isolate_importer.rb @@ -26,7 +26,7 @@ class IsolateImporter include Sidekiq::Worker - def perform(file, project_id) - Isolate.import(file, project_id) + def perform(file_path, project_id) + Isolate.import(file_path, project_id) end end \ No newline at end of file