Class: AtlasRb::Blob
Overview
The binary content backing a FileSet (or attached directly to a Work).
Blobs are the bytes-on-disk layer of the hierarchy. Operations on this class deal with raw octet streams: uploading new content, replacing content on an existing Blob, and streaming downloads via a chunk handler so very large files don't have to be buffered in memory.
Constant Summary collapse
- ROUTE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Atlas REST endpoint prefix for this resource.
"/files/"
Class Method Summary collapse
-
.content(id, nuid: nil, on_behalf_of: nil) {|chunk| ... } ⇒ Hash
Stream the Blob's binary content through a caller-supplied block.
-
.create(id, blob_path, original_filename, idempotency_key: nil, nuid: nil, on_behalf_of: nil) ⇒ Hash
Upload a new Blob attached to a Work.
-
.destroy(id, nuid: nil, on_behalf_of: nil) ⇒ Faraday::Response
Delete a Blob (the bytes and the metadata record).
-
.find(id, nuid: nil, on_behalf_of: nil) ⇒ Hash
Fetch a single Blob's metadata record (not its bytes — see Blob.content).
-
.update(id, blob_path, nuid: nil, on_behalf_of: nil) ⇒ Hash
Replace the bytes of an existing Blob in-place.
Methods inherited from Resource
Methods included from FaradayHelper
#connection, #multipart, #system_connection
Class Method Details
.content(id, nuid: nil, on_behalf_of: nil) {|chunk| ... } ⇒ Hash
Stream the Blob's binary content through a caller-supplied block.
The body is not buffered — each chunk Faraday receives is yielded
to chunk_handler immediately, making this safe for files larger than
available memory. The first chunk's response headers are captured and
returned so callers can inspect Content-Type, Content-Length, etc.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/atlas_rb/blob.rb', line 60 def self.content(id, nuid: nil, on_behalf_of: nil, &chunk_handler) headers = {} connection({}, nuid, on_behalf_of: on_behalf_of).get("#{ROUTE}#{id}/content") do |req| req..on_data = proc do |chunk, _bytes_received, env| headers = env.response_headers if headers.empty? && env chunk_handler.call(chunk) end end headers end |
.create(id, blob_path, original_filename, idempotency_key: nil, nuid: nil, on_behalf_of: nil) ⇒ Hash
Upload a new Blob attached to a Work.
original_filename is preserved separately from the upload's
File.basename(blob_path) because the on-disk path is often a temp
file name (RackMultipart...tmp) — Atlas needs the user-facing name
for download UX.
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/atlas_rb/blob.rb', line 101 def self.create(id, blob_path, original_filename, idempotency_key: nil, nuid: nil, on_behalf_of: nil) payload = { work_id: id, original_filename: original_filename, binary: Faraday::Multipart::FilePart.new(File.open(blob_path), "application/octet-stream", File.basename(blob_path)) } AtlasRb::Mash.new(JSON.parse( multipart(nuid, on_behalf_of: on_behalf_of, idempotency_key: idempotency_key) .post(ROUTE, payload)&.body ))['blob'] end |
.destroy(id, nuid: nil, on_behalf_of: nil) ⇒ Faraday::Response
Delete a Blob (the bytes and the metadata record).
127 128 129 |
# File 'lib/atlas_rb/blob.rb', line 127 def self.destroy(id, nuid: nil, on_behalf_of: nil) connection({}, nuid, on_behalf_of: on_behalf_of).delete(ROUTE + id) end |
.find(id, nuid: nil, on_behalf_of: nil) ⇒ Hash
Fetch a single Blob's metadata record (not its bytes — see content).
32 33 34 35 36 |
# File 'lib/atlas_rb/blob.rb', line 32 def self.find(id, nuid: nil, on_behalf_of: nil) AtlasRb::Mash.new(JSON.parse( connection({}, nuid, on_behalf_of: on_behalf_of).get(ROUTE + id)&.body ))['blob'] end |
.update(id, blob_path, nuid: nil, on_behalf_of: nil) ⇒ Hash
Replace the bytes of an existing Blob in-place.
The Blob ID is preserved; only the underlying content changes. The
original filename is not updated by this call — use a new
create if you need a different original_filename.
149 150 151 152 153 154 155 156 |
# File 'lib/atlas_rb/blob.rb', line 149 def self.update(id, blob_path, nuid: nil, on_behalf_of: nil) payload = { binary: Faraday::Multipart::FilePart.new(File.open(blob_path), "application/octet-stream", File.basename(blob_path)) } AtlasRb::Mash.new(JSON.parse( multipart(nuid, on_behalf_of: on_behalf_of).patch(ROUTE + id, payload)&.body )) end |