Sha256: 1d2ce33ec19a5811ec8186cc7cb89792d8c204511861f393a4115dea6d9e708f

Contents?: true

Size: 1.32 KB

Versions: 39

Compression:

Stored size: 1.32 KB

Contents

module Hydra::Controller::UploadBehavior
  
  # Creates a File Asset, adding the posted blob to the File Asset's datastreams and saves the File Asset
  #
  # @return [FileAsset] the File Asset  
  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
  
  # Puts the contents of params[:Filedata] (posted blob) into a datastream within the given @asset
  # Sets asset label and title to filename if they're empty
  #
  # @param [FileAsset] asset the File Asset to add the blob to
  # @param [#read] file the IO object that is the blob
  # @param [String] file the IO object that is the blob
  # @return [FileAsset] file the File Asset  
  def add_posted_blob_to_asset(asset, file, file_name)
    file_name ||= file.original_filename
    asset.add_file(file, datastream_id, file_name)
  end

  #Override this if you want to specify the datastream_id (dsID) for the created blob
  def datastream_id
    "content"
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
hydra-core-6.5.2 app/controllers/concerns/hydra/controller/upload_behavior.rb
hydra-core-6.5.1 app/controllers/concerns/hydra/controller/upload_behavior.rb
hydra-core-6.4.2 app/controllers/concerns/hydra/controller/upload_behavior.rb
hydra-core-7.0.0.rc1 app/controllers/concerns/hydra/controller/upload_behavior.rb
hydra-core-7.0.0.pre3 app/controllers/concerns/hydra/controller/upload_behavior.rb
hydra-core-6.5.0 app/controllers/concerns/hydra/controller/upload_behavior.rb
hydra-core-6.5.0.rc2 app/controllers/concerns/hydra/controller/upload_behavior.rb
hydra-core-7.0.0.pre2 app/controllers/concerns/hydra/controller/upload_behavior.rb
hydra-core-7.0.0.pre1 app/controllers/concerns/hydra/controller/upload_behavior.rb
hydra-core-6.4.1 app/controllers/concerns/hydra/controller/upload_behavior.rb
hydra-core-6.4.0 app/controllers/concerns/hydra/controller/upload_behavior.rb
hydra-core-6.4.0.rc5 app/controllers/concerns/hydra/controller/upload_behavior.rb
hydra-core-6.4.0.rc4 lib/hydra/controller/upload_behavior.rb
hydra-core-6.4.0.rc3 lib/hydra/controller/upload_behavior.rb
hydra-core-6.4.0.rc2 lib/hydra/controller/upload_behavior.rb
hydra-core-6.4.0.rc1 lib/hydra/controller/upload_behavior.rb
hydra-core-6.4.0.pre2 lib/hydra/controller/upload_behavior.rb
hydra-core-6.4.0.pre1 lib/hydra/controller/upload_behavior.rb
hydra-core-6.3.4 lib/hydra/controller/upload_behavior.rb
hydra-core-6.3.3 lib/hydra/controller/upload_behavior.rb