Skip to content

Commit

Permalink
Merge pull request #472 from scientist-softserv/s3_direct_downloads
Browse files Browse the repository at this point in the history
download straight from the s3 bucket iwth displosbale s3 links.
  • Loading branch information
orangewolf authored Sep 23, 2023
2 parents 153c457 + 38d5ad7 commit a2587c3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/controllers/hyrax/downloads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ def item_identifier_for_irus_analytics

private

# OVERRIDE Hyrax 2.9.6 allow downloading directly from S3
def send_file_contents
if ENV['S3_DOWNLOADS']
s3_object = Aws::S3::Object.new(ENV['AWS_BUCKET'], file.digest.first.to_s.gsub('urn:sha1:', ''))
redirect_to s3_object.presigned_url(:get, expires_in: 300, response_content_disposition: "attachment\; filename=#{file.original_name}")
else
self.status = 200
prepare_file_headers
stream_body file.stream
end
end

# Override the Hydra::Controller::DownloadBehavior#content_options so that
# we have an attachement rather than 'inline'
def content_options
Expand Down
10 changes: 10 additions & 0 deletions ops/production-deploy.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ extraEnvVars: &envVars
value: "1"
- name: EXTERNAL_IIIF_URL
value: https://dudgkgvsbllzg.cloudfront.net/iiif/2
- name: AWS_BUCKET
value: "samvera-fcrepo-staging-bl"
- name: AWS_ACCESS_KEY_ID
value: $AWS_ACCESS_KEY_ID
- name: AWS_SECRET_ACCESS_KEY
value: $AWS_SECRET_ACCESS_KEY
- name: AWS_REGION
value: 'eu-west-1'
- name: S3_DOWNLOADS
value: "true"

worker:
replicaCount: 1
Expand Down
10 changes: 10 additions & 0 deletions ops/staging-deploy.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ ingress:
secretName: notch8cloudstaging

extraEnvVars: &envVars
- name: AWS_BUCKET
value: "samvera-fcrepo-staging-bl"
- name: AWS_ACCESS_KEY_ID
value: $AWS_ACCESS_KEY_ID
- name: AWS_SECRET_ACCESS_KEY
value: $AWS_SECRET_ACCESS_KEY
- name: AWS_REGION
value: 'eu-west-1'
- name: CONFDIR
value: "/app/samvera/hyrax-webapp/solr/config"
- name: DATABASE_ADAPTER
Expand Down Expand Up @@ -129,6 +137,8 @@ extraEnvVars: &envVars
value: "true"
- name: HYKU_ROOT_HOST
value: bl-staging.notch8.cloud
- name: S3_DOWNLOADS
value: "true"
- name: SMTP_ADDRESS
value: smtp.mailtrap.io
- name: SMTP_DOMAIN
Expand Down

0 comments on commit a2587c3

Please sign in to comment.