Sha256: c7136f26f18b44c18de0da2cfe9d79e3a26daa094ad59536ff41eec6c33f9e02
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
require 'net/https' require 'uri' require 'tempfile' class ImportUrlJob < ActiveFedoraIdBasedJob queue_as :import_url def perform(id) @id = id user = User.find_by_user_key(file_set.depositor) Tempfile.open(id.tr('/', '_')) do |f| copy_remote_file(file_set.import_url, f) # attach downloaded file to generic file stubbed out if CurationConcerns::FileSetActor.new(file_set, user).create_content(f) # send message to user on download success CurationConcerns.config.callback.run(:after_import_url_success, file_set, user) else CurationConcerns.config.callback.run(:after_import_url_failure, file_set, user) end end end def copy_remote_file(_import_url, f) f.binmode # download file from url uri = URI(file_set.import_url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == 'https' # enable SSL/TLS http.verify_mode = OpenSSL::SSL::VERIFY_NONE mime_type = nil http.start do http.request_get(uri.request_uri) do |resp| mime_type = resp.content_type resp.read_body do |segment| f.write(segment) end end end f.rewind end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
curation_concerns-models-0.3.0 | app/jobs/import_url_job.rb |
curation_concerns-models-0.2.0 | app/jobs/import_url_job.rb |