-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* for direct upload to s3 * for direct upload (and download) to (and from) s3 * add the file_actor_decorator with the s3 upload code in it... 1GB threshold * we've already subclassed file_set_indexer so leave decorator alone for onel line change * pulled over * debug import url errors * turnoff puma-hang-on * more debug for importUrlJob * remove rescue get error * remove url_job_override, update RObs code to fit the Hyrax version we are using * add some debug to downloads controller to see what's up with filename * don't use the S3 URL to name the file * file_set.filename not file_set.file_name :/ * debug * remove debug, using @file_set.label for file.file_name when doing the external file attaching thing
- Loading branch information
Showing
8 changed files
with
95 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module Hyrax | ||
module Actors | ||
# Actions for a file identified by file_set and relation (maps to use predicate) | ||
# @note Spawns asynchronous jobs | ||
module FileActorDecorator | ||
def ingest_file(io) | ||
Rails.logger.error("[FileActor] starting write for #{file_set.id}") | ||
if io.size.to_i >= 1.gigabytes | ||
Rails.logger.error("[FileActor] Uploading directly to S3 for file_set #{file_set.id}") | ||
digest = `sha1sum #{io.path}`.split.first | ||
file_set.s3_only = digest | ||
s3_object = Aws::S3::Object.new(ENV['AWS_BUCKET'], digest) | ||
s3_object.upload_file(io.path) unless s3_object.exists? | ||
Hydra::Works::AddExternalFileToFileSet.call(file_set, s3_object.public_url, relation) | ||
# how do we make sure the sha gets indexed? | ||
else | ||
Rails.logger.error("[FileActor] writing to fcrepo #{file_set.id}") | ||
# Skip versioning because versions will be minted by VersionCommitter as necessary during save_characterize_and_record_committer. | ||
Hydra::Works::AddFileToFileSet.call(file_set, | ||
io, | ||
relation, | ||
versioning: false) | ||
end | ||
return false unless file_set.save | ||
repository_file = related_file | ||
Hyrax::VersioningService.create(repository_file, user) | ||
pathhint = io.uploaded_file.uploader.path if io.uploaded_file # in case next worker is on same filesystem | ||
CharacterizeJob.perform_later(file_set, repository_file.id, pathhint || io.path) | ||
end | ||
end | ||
end | ||
end | ||
|
||
Hyrax::Actors::FileActor.prepend(Hyrax::Actors::FileActorDecorator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
lib/hydra/works/services/add_external_file_to_file_set_decorator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# OVERRIDE Hydra-works 2.0.0 to deal with fcrepo + s3s inability to upload empty files | ||
|
||
module Hydra | ||
module Works | ||
module UpdaterDecorator | ||
def attach_attributes(external_file_url, filename = nil) | ||
current_file.content = StringIO.new('-') # anything but blank | ||
# filename will be the url.... but we will use file_set.label | ||
# becuase making the filename the url of an s3 key is problematic for humans | ||
current_file.original_name = @file_set.label | ||
current_file.mime_type = "message/external-body; access-type=URL; URL=\"#{external_file_url}\"" | ||
end | ||
end | ||
end | ||
end | ||
|
||
Hydra::Works::AddExternalFileToFileSet::Updater.prepend(Hydra::Works::UpdaterDecorator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters