diff --git a/app/controllers/concerns/downloadable_controller.rb b/app/controllers/concerns/downloadable_controller.rb index b001a804e408e16edec0327332f0d5aeb8ac8d1b..e7e872cfeac592c2fa8e506dab3674c567d1b14c 100644 --- a/app/controllers/concerns/downloadable_controller.rb +++ b/app/controllers/concerns/downloadable_controller.rb @@ -22,30 +22,25 @@ module DownloadableController # GET /learning_objects/1/download def download - - Rails.logger.info "\n\nSo far... \nSo good...\n\n" - object_id = params.values[2] - Rails.logger.info "This is my learning_object id: #{object_id}\n\n" - + object = LearningObject.where(id: object_id).first + attachment_id = object.attachment_id + + attachment = LearningObject::Attachment.where(id: attachment_id).first.as_json - # how it used to be (not working) # - # Change request.remote_ip to req.env["HTTP_X_REAL_IP"] in production - # downloadable.download(current_user, request.remote_ip) - # link = downloadable.download_link - # if !link.blank? - # redirect_to link - # else - # render status: :internal_server_error - # end - + attachment_name = attachment["name"] + link = attachment["retrieve_link"] + source = "https://mecdb4.c3sl.ufpr.br:8443" + link + + require 'open-uri' + + data = URI.open(source) + send_data data, :disposition => 'attachment', :filename=>attachment_name - # an idea on how to proceed # - # extension= #get file extension - # send_file Rails.root.join('public', 'uploads', #file), - # :type=>"aplicattion/#{extension[1]}", :x_sendfile=>true + # https://mecdb4.c3sl.ufpr.br:8443/rest/bitstreams/11104/retrieve + # https://api.portalmec.c3sl.ufpr.br/v1/learning_objects/10943/download end protected