Class: Backup::Backblaze::UploadFile
- Inherits:
-
Object
- Object
- Backup::Backblaze::UploadFile
- Extended by:
- ApiImporter
- Defined in:
- lib/backup/backblaze/upload_file.rb
Overview
calculates sha1 and uploads file Of course, this entire class is an atomic failure, because the underlying file could change at any point.
dst can contain / for namespaces
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#bucket_id ⇒ Object
readonly
Returns the value of attribute bucket_id.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#dst ⇒ Object
readonly
Returns the value of attribute dst.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
Instance Method Summary collapse
-
#b2_authorize_account(retries:, backoff:) ⇒ Object
needed for retry logic.
- #call ⇒ Object
-
#content_disposition ⇒ Object
No idea what has to be in here.
- #content_length ⇒ Object
- #headers ⇒ Object
-
#initialize(account:, src:, bucket_id:, dst:, url_token: nil, content_type: nil) ⇒ UploadFile
constructor
A new instance of UploadFile.
- #last_modified_millis ⇒ Object
- #sha1 ⇒ Object
- #sha1_digest ⇒ Object
- #url_token ⇒ Object
Methods included from ApiImporter
Constructor Details
#initialize(account:, src:, bucket_id:, dst:, url_token: nil, content_type: nil) ⇒ UploadFile
Returns a new instance of UploadFile.
13 14 15 16 17 18 19 20 |
# File 'lib/backup/backblaze/upload_file.rb', line 13 def initialize account:, src:, bucket_id:, dst:, url_token: nil, content_type: nil @account = account @src = src @dst = dst @content_type = content_type @bucket_id = bucket_id @url_token = url_token end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
22 23 24 |
# File 'lib/backup/backblaze/upload_file.rb', line 22 def account @account end |
#bucket_id ⇒ Object (readonly)
Returns the value of attribute bucket_id.
22 23 24 |
# File 'lib/backup/backblaze/upload_file.rb', line 22 def bucket_id @bucket_id end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
22 23 24 |
# File 'lib/backup/backblaze/upload_file.rb', line 22 def content_type @content_type end |
#dst ⇒ Object (readonly)
Returns the value of attribute dst.
22 23 24 |
# File 'lib/backup/backblaze/upload_file.rb', line 22 def dst @dst end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
22 23 24 |
# File 'lib/backup/backblaze/upload_file.rb', line 22 def src @src end |
Instance Method Details
#b2_authorize_account(retries:, backoff:) ⇒ Object
needed for retry logic
72 73 74 |
# File 'lib/backup/backblaze/upload_file.rb', line 72 def (retries:, backoff:) account. retries: retries, backoff: backoff end |
#call ⇒ Object
93 94 95 96 97 |
# File 'lib/backup/backblaze/upload_file.rb', line 93 def call Backup::Logger.info "uploading '#{dst}' of #{src.size}" url_token # not necessary, but makes the flow of control more obvious in the logs b2_upload_file end |
#content_disposition ⇒ Object
No idea what has to be in here
47 48 |
# File 'lib/backup/backblaze/upload_file.rb', line 47 def content_disposition end |
#content_length ⇒ Object
50 51 52 |
# File 'lib/backup/backblaze/upload_file.rb', line 50 def content_length File.size src end |
#headers ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/backup/backblaze/upload_file.rb', line 28 def headers # headers all have to be strings, otherwise excon & Net::HTTP choke :-| { 'X-Bz-File-Name' => (URI.encode dst.encode 'UTF-8'), 'X-Bz-Content-Sha1' => sha1_digest, 'Content-Length' => content_length.to_s, 'Content-Type' => content_type, # optional 'X-Bz-Info-src_last_modified_millis' => last_modified_millis.to_s, 'X-Bz-Info-b2-content-disposition' => content_disposition, }.merge(TEST_HEADERS).select{|k,v| v} end |
#last_modified_millis ⇒ Object
62 63 64 65 66 67 |
# File 'lib/backup/backblaze/upload_file.rb', line 62 def last_modified_millis @last_modified_millis ||= begin time = File.lstat(src).mtime time.tv_sec * 1000 + time.tv_usec / 1000 end end |
#sha1 ⇒ Object
54 55 56 |
# File 'lib/backup/backblaze/upload_file.rb', line 54 def sha1 @sha1 = Digest::SHA1.file src end |
#sha1_digest ⇒ Object
58 59 60 |
# File 'lib/backup/backblaze/upload_file.rb', line 58 def sha1_digest @sha1_digest = sha1.hexdigest end |
#url_token ⇒ Object
24 25 26 |
# File 'lib/backup/backblaze/upload_file.rb', line 24 def url_token @url_token or b2_get_upload_url end |