diff --git a/config/initializers/import_url_job_overrides.rb b/config/initializers/import_url_job_overrides.rb index 2447fcd7..58b97356 100644 --- a/config/initializers/import_url_job_overrides.rb +++ b/config/initializers/import_url_job_overrides.rb @@ -1,5 +1,22 @@ ImportUrlJob.class_eval do + def copy_remote_file(uri, name, headers = {}) + filename = File.basename(name) + dir = Dir.mktmpdir + Rails.logger.debug("ImportUrlJob: Copying <#{uri}> to #{dir}") + + File.open(File.join(dir, filename), 'wb') do |f| + begin + write_file(uri, f, headers) + yield f + rescue StandardError => e + STDERR.puts("IMPORT URL ERROR: #{e}") + send_error(e.message) + end + end + Rails.logger.debug("ImportUrlJob: Closing #{File.join(dir, filename)}") + end + def send_error(error_message) user = User.find_by_user_key(file_set.depositor) @file_set.errors.add('Error:', error_message)