class Backup::Backblaze::UploadFile

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

Attributes

account[R]
bucket_id[R]
content_type[R]
dst[R]
src[R]

Public Class Methods

new(account:, src:, bucket_id:, dst:, url_token: nil, content_type: nil) click to toggle source
# 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

Public Instance Methods

b2_authorize_account(retries:, backoff:) click to toggle source

needed for retry logic

# File lib/backup/backblaze/upload_file.rb, line 72
def b2_authorize_account(retries:, backoff:)
  account.b2_authorize_account retries: retries, backoff: backoff
end
call() click to toggle source
# 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() click to toggle source

No idea what has to be in here

# File lib/backup/backblaze/upload_file.rb, line 47
def content_disposition
end
content_length() click to toggle source
# File lib/backup/backblaze/upload_file.rb, line 50
def content_length
  File.size src
end
headers() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/backup/backblaze/upload_file.rb, line 54
def sha1
  @sha1 = Digest::SHA1.file src
end
sha1_digest() click to toggle source
# File lib/backup/backblaze/upload_file.rb, line 58
def sha1_digest
  @sha1_digest = sha1.hexdigest
end
url_token() click to toggle source
# File lib/backup/backblaze/upload_file.rb, line 24
def url_token
  @url_token or b2_get_upload_url
end