class TpCommon::FileStorage::Uploaders::Private

Upload a content to file storage used for private purpose like user import. export files Use in case content to upload is inside of system/server

Public Instance Methods

exists?(file_key) click to toggle source

@param file_key [String]

# File lib/tp_common/file_storage/uploaders/private.rb, line 39
def exists?(file_key)
  !!directory.files.head(mask_key(file_key))
end
upload(file_key, content, content_type) click to toggle source

Upload content to file_key

# File lib/tp_common/file_storage/uploaders/private.rb, line 10
def upload(file_key, content, content_type)
  retry_count = 0

  begin
    directory.files.create(
      'key' => mask_key(file_key),
      "body" =>  content,
      'public' =>  false,
      'Content-Type' => content_type,
      "Content-Disposition" => "attachment;filename=\"#{mask_key(file_key)}\""
    )
  rescue StandardError => e
    retry_count += 1
    retry if retry_count < MAX_RETRIES
    raise e
  end

  mask_key(file_key)
end
url(file_key, link_ttl = 1.week.from_now) click to toggle source

Get url from key of file upload above to provide to outside.

To get file content to use inside system, please use Downloaders::Private instead

As private file, link has a ttl, default 1 week.

# File lib/tp_common/file_storage/uploaders/private.rb, line 34
def url(file_key, link_ttl = 1.week.from_now)
  directory.files.get_https_url(mask_key(file_key), link_ttl)
end