Skip to content

Commit

Permalink
chore: revert to using copy blob from url option and update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
ericenns committed Feb 6, 2025
1 parent 9e1bbbe commit 674fe68
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## [Unreleased]

- Add `copy_blob`
- Update `compose` to use `copy_blob` if 1 source key and blob is <= 256MiB

## [0.5.6] 2025-01-17

- Fix user delegation key not refreshing (#14)
Expand Down
4 changes: 2 additions & 2 deletions lib/active_storage/service/azure_blob_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def compose(source_keys, destination_key, filename: nil, content_type: nil, disp
content_disposition = content_disposition_with(type: disposition, filename: filename) if disposition && filename

# use copy_blob operation if composing a new blob from a single existing blob
# and that single blob is <= 5000 MiB which is the upper limit for copy_blob operation
if source_keys.length == 1 && client.get_blob_properties(source_keys[0]).size <= 5000.megabytes
# and that single blob is <= 256 MiB which is the upper limit for copy_blob operation
if source_keys.length == 1 && client.get_blob_properties(source_keys[0]).size <= 256.megabytes
client.copy_blob(destination_key, source_keys[0], metadata: custom_metadata)
else
client.create_append_blob(
Expand Down
5 changes: 2 additions & 3 deletions lib/azure_blob/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_blob(key, options = {})

# Copy a blob
#
# Calls to {Put Blob From URL}[https://learn.microsoft.com/en-us/rest/api/storageservices/put-blob-from-url]
# Calls to {Put Blob From URL}[https://learn.microsoft.com/en-us/rest/api/storageservices/copy-blob-from-url]
#
# Takes a key (path) and a source_key (path).
#
Expand All @@ -89,9 +89,8 @@ def copy_blob(key, source_key, options = {})
source_uri = signed_uri(source_key, permissions: "r", expiry: Time.at(Time.now.to_i + 300).utc.iso8601)

headers = {
"Content-Length": 0,
"x-ms-copy-source": source_uri.to_s,
"x-ms-blob-type": "BlockBlob",
"x-ms-requires-sync": "true",
}

Http.new(uri, headers, signer:, **options.slice(:metadata, :tags)).put
Expand Down

0 comments on commit 674fe68

Please sign in to comment.