-
Notifications
You must be signed in to change notification settings - Fork 41
File downloads
David Chandek-Stark edited this page Apr 16, 2014
·
9 revisions
class DownloadsController < ApplicationController
include Hydra::Controller::DownloadBehavior
end
then in config/routes.rb add resources :downloads
then you can do a GET /downloads/{pid}?datastream_id=thumbnail
to get the thumbnail datastream
By default this allows any user with read access to the object identified by pid to download any of the datastreams. If you want to control which datastreams a user has access to:
In hydra-head versions >= 7.0, override the download_permissions
method of Hydra::Ability
# This example allows anyone to download a 'thumbnail' datastream
# and requires read access to download other datastreams
def download_permissions
can :download, ActiveFedora::Datastream do |ds|
ds.dsid == 'thumbnail' || can?(:read, ds.pid)
end
end
In hydra-head versions < 7.0, override the can_download?
method of Hydra::Controller::DownloadBehavior
.
# This example allows anyone to download a 'thumbnail' datastream
def can_download?
datastream.dsid == 'thumbnail'
end