Skip to content
Snippets Groups Projects
Commit a4cedb76 authored by nar20's avatar nar20
Browse files

[add] new download route

parent 9d7185d3
No related branches found
No related tags found
1 merge request!56Issue/61 download colections
Pipeline #38213 failed
...@@ -22,30 +22,25 @@ module DownloadableController ...@@ -22,30 +22,25 @@ module DownloadableController
# GET /learning_objects/1/download # GET /learning_objects/1/download
def download def download
Rails.logger.info "\n\nSo far... \nSo good...\n\n"
object_id = params.values[2] 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
attachment_name = attachment["name"]
# how it used to be (not working) # link = attachment["retrieve_link"]
# Change request.remote_ip to req.env["HTTP_X_REAL_IP"] in production source = "https://mecdb4.c3sl.ufpr.br:8443" + link
# downloadable.download(current_user, request.remote_ip)
# link = downloadable.download_link
# if !link.blank?
# redirect_to link
# else
# render status: :internal_server_error
# end
require 'open-uri'
data = URI.open(source)
send_data data, :disposition => 'attachment', :filename=>attachment_name
# an idea on how to proceed # # https://mecdb4.c3sl.ufpr.br:8443/rest/bitstreams/11104/retrieve
# extension= #get file extension # https://api.portalmec.c3sl.ufpr.br/v1/learning_objects/10943/download
# send_file Rails.root.join('public', 'uploads', #file),
# :type=>"aplicattion/#{extension[1]}", :x_sendfile=>true
end end
protected protected
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment