rails_console - UW-Libraries/druw GitHub Wiki
##Creating a work in hyrax from the rails console##
I modified Aaron Collier's packager.rake.
This will allow you to load large files.
# doesn't have to be production
$ rails c production
# Create a blank array to hold uploaded files
> uploadedFiles = Array.new
# Get an existing user into a variable
> depositor = User.find_by_user_key("[email protected]")
# Create a hash and fill it with metadata
> params = Hash.new {|h,k| h[k]=[]}
> params["title"] = ["Thing3 - console large file"]
> params["creator"] = ["me"]
> params["admin_set_id"] = "admin_set/default"
# Create a Hyrax GenericWork and add metadata in params
> item = GenericWork.new(id: ActiveFedora::Noid::Service.new.mint)
> item.update(params)
> item.apply_depositor_metadata(depositor.user_key)
> item.save
# Upload some files and add it to uploadedFiles array
> file = File.open("/vagrant/kenmorebear.jpg")
> hyraxFile = Hyrax::UploadedFile.create(file: file)
> hyraxFile.save
> uploadedFiles.push(hyraxFile)
> file.close
> file = File.open("/vagrant/example.pdf")
> hyraxFile = Hyrax::UploadedFile.create(file: file)
> hyraxFile.save
> uploadedFiles.push(hyraxFile)
> file.close
# Attach uploaded files to the instance of the GenericWork created above.
> workFiles = AttachFilesToWorkJob.perform_now(item,uploadedFiles)
Problems
- loading more than one file doesn't complete second file characterization.
- Can't figure out how to get some of the metadata values,
- date_uploaded and date_modified. I guess I could just do time.now
- state: #<ActiveTriples::Resource:0x4bc8dd4(#ActiveTriples::Resource:0x00000009791ba8)>,
- jpg loads but no thumbnail, no file characterization. (Solved by setting FITS_HOME)
Characterization of uploaded files
Sometimes file characterization fails to run on upload.
# Set FITS_HOME
export FITS_HOME=/usr/local/bin/fits
sudo rails c production
# Get the fileset_id from browser url. Eg.http://localhost:4000/concern/parent/79407x16z/file_sets/rf55z768s
> fs = FileSet.find("rf55z768s")
# Get the file_id.
> f = fs.files[0]
=> #<Hydra::PCDM::File uri="http://127.0.0.1:8080/fedora/rest/prod/rf/55/z7/68/rf55z768s/files/2c93d79d-60dd-4117-86fb-2f8ac860a066" >
> fid = f.id
=> "rf55z768s/files/2c93d79d-60dd-4117-86fb-2f8ac860a066"
# Run the characterization job
> CharacterizeJob.perform_now(f,fid)
or
> CharacterizeJob.perform_now(f,"rf55z768s/files/2c93d79d-60dd-4117-86fb-2f8ac860a066","/var/hyrax/tmp/uploads/hyrax/uploaded_file/file/3/kenmorebear.jpg")