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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91def17491b8ea4a04f7c03cac167a712e633d7297e679ec42d0149674cdcc68
4
- data.tar.gz: 8b31f27d7574a7e70b863d5341aabb79084a7668c8a6af4ff6eb649f42065964
3
+ metadata.gz: d9f30d16a6f60418e327603c2c2a88f2305bbb4178bcd681143e44ba2a5980d1
4
+ data.tar.gz: bb585ce6e143dbcfc3ab262a398b35b44793a352c164a6211abeac12c2e64faa
5
5
  SHA512:
6
- metadata.gz: 1d7b8c31aa2b7da9ea211f32a65b61239b065e7984ca2f5e444049585b87cf8b3026725ba931679476c838cf79af880fcd56eba2ed2eee578be69692c04eeb68
7
- data.tar.gz: 79dbff0c379557b22cf7f8ab76bb1140d43ce21e7348026fbe88a0dda39b455e3908e04d9744694d258312ada353fc66cc139267a0c48b96a302a6db8566f702
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
- @connection.put_object(@bucket_name, key, io)
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
- raise NotImpletementedError
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
- raise NotImpletementedError
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activestorage-backblaze
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jey