Module: Hydra::Controller::UploadBehavior

Defined in:
lib/hydra/controller/upload_behavior.rb

Instance Method Summary collapse

Instance Method Details

#add_posted_blob_to_asset(asset, file, file_name) ⇒ FileAsset

Puts the contents of params (posted blob) into a datastream within the given @asset Sets asset label and title to filename if they’re empty

Parameters:

  • asset (FileAsset)

    the File Asset to add the blob to

  • file (#read)

    the IO object that is the blob

  • file (String)

    the IO object that is the blob

Returns:



29
30
31
32
# File 'lib/hydra/controller/upload_behavior.rb', line 29

def add_posted_blob_to_asset(asset, file, file_name)
  file_name ||= file.original_filename
  asset.add_file(file, datastream_id, file_name)
end

#create_and_save_file_assets_from_paramsFileAsset

Creates a File Asset, adding the posted blob to the File Asset’s datastreams and saves the File Asset

Returns:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/hydra/controller/upload_behavior.rb', line 6

def create_and_save_file_assets_from_params
  if params.has_key?(:Filedata)
    @file_assets = []
    params[:Filedata].each do |file|
      @file_asset = FileAsset.new
      @file_asset.label = file.original_filename
      add_posted_blob_to_asset(@file_asset, file, file.original_filename)
      @file_asset.save!
      @file_assets << @file_asset
    end
    return @file_assets
  else
    render :text => "400 Bad Request", :status => 400
  end
end

#datastream_idObject

Override this if you want to specify the datastream_id (dsID) for the created blob



35
36
37
# File 'lib/hydra/controller/upload_behavior.rb', line 35

def datastream_id
  "content"
end