activestorage-backblaze 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_storage/service/backblaze_service.rb +25 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9f30d16a6f60418e327603c2c2a88f2305bbb4178bcd681143e44ba2a5980d1
|
4
|
+
data.tar.gz: bb585ce6e143dbcfc3ab262a398b35b44793a352c164a6211abeac12c2e64faa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 432e3f72c9f1b080ec745abe0bf6b25085a6bd379e6078f157f61095d2e10e9397ded0749ec4d286a318b1b594b1255f211788cd12218d3e3856dba540916889
|
7
|
+
data.tar.gz: 29415b2661d2dd5b32bd5135e67cbb27047c4bcd9d3b489b77b329aabb1d0d0d50dbaf9c64afe36e3a7ebb73a0f308ce44decb17ffa27fb1b10aae9bc7536ab3
|
@@ -19,8 +19,12 @@ class ActiveStorage::Service::BackblazeService < ActiveStorage::Service
|
|
19
19
|
def upload(key, io, checksum: nil, **options)
|
20
20
|
instrument :upload, { key: key, checksum: checksum } do
|
21
21
|
begin
|
22
|
-
|
22
|
+
io.binmode
|
23
|
+
io.rewind
|
24
|
+
@connection.put_object(@bucket_name, key, io.read)
|
23
25
|
rescue => e
|
26
|
+
puts "ERROR - 101"
|
27
|
+
puts e.inspect
|
24
28
|
raise ActiveStorage::IntegrityError
|
25
29
|
end
|
26
30
|
end
|
@@ -77,11 +81,17 @@ class ActiveStorage::Service::BackblazeService < ActiveStorage::Service
|
|
77
81
|
end
|
78
82
|
|
79
83
|
def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:)
|
80
|
-
|
84
|
+
instrument :url, { key: key} do |payload|
|
85
|
+
result = @connection.b2_get_upload_url(@bucket_name)
|
86
|
+
url = result["uploadUrl"]
|
87
|
+
payload[:url] = url
|
88
|
+
url
|
89
|
+
end
|
81
90
|
end
|
82
91
|
|
83
|
-
def headers_for_direct_upload(key, content_type:, checksum:, **)
|
84
|
-
|
92
|
+
def headers_for_direct_upload(key, content_type:, checksum:, content_length:, **options)
|
93
|
+
result = @connection.b2_get_upload_url(@bucket_name)
|
94
|
+
{ 'Authorization' => result["authorizationToken"], 'X-Bz-File-Name' => key, 'Content-Type' => content_type, 'Content-Length' => content_length, 'X-Bz-Content-Sha1' => 'do_not_verify' }
|
85
95
|
end
|
86
96
|
|
87
97
|
private
|
@@ -98,3 +108,14 @@ class ActiveStorage::Service::BackblazeService < ActiveStorage::Service
|
|
98
108
|
end
|
99
109
|
|
100
110
|
end
|
111
|
+
|
112
|
+
class Fog::Backblaze::Storage::Real
|
113
|
+
def b2_get_upload_url(bucket_name)
|
114
|
+
upload_url = @token_cache.fetch("upload_url/#{bucket_name}") do
|
115
|
+
bucket_id = _get_bucket_id!(bucket_name)
|
116
|
+
result = b2_command(:b2_get_upload_url, body: {bucketId: bucket_id})
|
117
|
+
result.json
|
118
|
+
end
|
119
|
+
upload_url
|
120
|
+
end
|
121
|
+
end
|