class TpCommon::FileStorage::Uploaders::Public

Upload a content to file storage used to public like avatar, logo 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/public.rb, line 35
def exists?(file_key)
  !!directory.files.head(mask_key(file_key))
end
upload(file_key, content, _content_type = nil) click to toggle source

Upload content to file_key Currently, _content_type is ignore but kept for compatible. Will be removed in next release

# File lib/tp_common/file_storage/uploaders/public.rb, line 11
def upload(file_key, content, _content_type = nil)
  retry_count = 0

  begin
    directory.files.create(
      key: mask_key(file_key),
      body: content,
      public: true)
  rescue StandardError => e
    retry_count += 1
    retry if retry_count < MAX_RETRIES
    raise e
  end

  mask_key(file_key)
end
url(file_key) click to toggle source

Get public url from key of file upload above

# File lib/tp_common/file_storage/uploaders/public.rb, line 30
def url(file_key)
  directory.files.get(mask_key(file_key))&.public_url
end